How and when to use JPA’s getReference() Method

How and when to use JPA’s getReference() Method

With the T getReference(Class<T> entityClass, Object primaryKey) and the T find(Class<T> entityClass, Object primaryKey) method, JPA’s EntityManager seems to provide 2 methods that do the same. Both of them seem to get an entity by its primary key from the database. There obviously is a difference between the 2 methods. An established and well-defined API…

Hibernate’s Read-Only Query Hint For Faster Read Operations

Hibernate’s Read-Only Query Hint For Faster Read Operations

By default, Hibernate loads all entity objects in read-write mode. It performs dirty checks to detect changes it needs to persist in your database for each of them. That makes entities very easy to use, but it also creates an overhead if you don’t want to change anything. You can avoid this by setting Hibernate’s…

Hibernate’s Query Plan Cache – How It Works and How to Tune It

Hibernate’s Query Plan Cache – How It Works and How to Tune It

Hibernate’s Query Plan Cache speeds up the preparation of your queries. That reduces their overall execution time, and improves the performance of your application. In the test scenario of this article, it improved the performance of the query preparation by up to 500%. To make it even better, Hibernate does all of that automatically. The…

Hibernate Proxies – Why they’re used and how to unproxy them

Hibernate Proxies – Why they’re used and how to unproxy them

Hibernate generates proxies to provide lazy loading for to-one associations, and you can use them to improve the performance of some of your write operations. You might have seen the class names of these proxies in your debugger or some log messages. They consist of the name of your entity class and a postfix that…