Common Hibernate operations
In this section, you will learn some of the common Hibernate operations which are used to process data from the database.
The following are some of the key operations:
- Data retrieval
- Save/persist
- Update/merge
- Save or update
Data retrieval
Data retrieval can be done using NamedQuery, Criteria, or a simple Hibernate query mechanism as illustrated in the previous sections. Here are the best practices:
- Criteria can be used to dynamically create queries at runtime. The usage of Criteria for static queries should be avoided due to the disadvantages, such as cost, associated with translating a JPQL query to SQL every time it is accessed.
- NamedQuery allows queries to be accessed using alias names while making it easy to manage queries. NamedQuery is the preferred choice for static queries.
Save/persist operation
Transient instances of persistent classes can be saved in the database using Session APIs such as save or persist. Transient instances are the one which do not have any...