Hibernate Session Interface - save()| how to communicate with Database#hibernate #java

preview_player
Показать описание
Session interface is a single threaded object. The wrapping of a JDBC connection is the emphasized role of a Session interface object. This is the major interface between Java application and Hibernate. This is a runtime interface. The purpose of this interface is to perform create, read and delete operations for the objects that are mapped with entity classes.

beginTransaction()
Begin a unit of work and return the associated Transaction object. This method needs to be called if you want to enable transaction, and once your DB interactions are done, call commit() method on the returned transaction object. Incase of any issues, call rollback() error on the transaction object.

save()
Persist the given transient instance, first assigning a generated identifier. This method stores the given object in the database. Before storing, it checks for generated identifier declaration and process it first, then it will store into DB.

update()
Update the persistent instance with the identifier of the given detached instance. It updates the database record.

saveOrUpdate()
Either save(Object) or update(Object) the given instance, depending upon resolution of the unsaved-value checks. This operation cascades to associated instances if the association is mapped with cascade="save-update".

createQuery()
Create a new instance of Query for the given HQL query string.

createSQLQuery()..
Рекомендации по теме
join shbcf.ru