How to query by entity type using JPA Criteria API

Introduction Inspired by this Hibernate forum post, I decided to write an article to explain how you can filter by the entity type using Criteria API.

How to map an immutable entity with JPA and Hibernate

Introduction In this article, you are going to find out how to map an immutable entity when using JPA and Hibernate. If your Domain Model requires that a given entity should not be modified by the data access logic, Hibernate can enforce this requirement if the entity is marked with the @Immutable annotation.

JPA Criteria API Bulk Update and Delete

Introduction JPA Criteria API bulk update delete is a great feature that allows you do build bulk update and delete queries using the JPA 2.1 Criteria API support via CriteriaUpdate and CriteriaDelete. Because one of our community members asked me on the Hibernate forum about this topic, I decided it is a good opportunity to write about this lesser-known JPA Criteria API feature.

How does Hibernate handle JPA Criteria API literals

Introduction The JPA specification is like a Java interface, However, when it comes to performance, implementation details matter a lot. That’s why, even if you use the JPA standard, you still need to know how the underlying provider implements the standard specification. For instance, if we take this tweet from Gareth Western: We can clearly see that there is an issue in the way literals might be handled by Hibernate when executing a Criteria API query. Therefore, in this article, we are going to see how literals are handled by Hibernate and… Read More

EAGER fetching is a code smell when using JPA and Hibernate

Introduction Hibernate fetching strategies can really make a difference between an application that barely crawls and a highly responsive one. In this post, I’ll explain why you should prefer query based fetching instead of global fetch plans. Fetching 101 Hibernate defines four association retrieving strategies: Fetching Strategy Description Join The association is OUTER JOINED in the original SELECT statement Select An additional SELECT statement is used to retrieve the associated entity(entities) Subselect An additional SELECT statement is used to retrieve the whole associated collection. This mode is meant for to-many associations Batch… Read More