Hibernate supports a useful feature that actually helps to improve the performance of the application by reducing the processing time. The feature we are talking about here is called query cache.
Hibernate caches the query result, which is frequently used. This feature is only useful if the same queries are executed frequently.
To understand the query cache, we will use the Employee
POJO that was created in the previous recipe entitled Working with a first-level cache. We also need to modify hibernate.cfg.xml
to enable the query cache feature:
Source file: Employee.java
@Entity public class Employee { @Id @GeneratedValue private long id; @Column(name = "name") private String name; // getters and setters }