How to parse a String into an EntityGraph with Hibernate 5.4
|

How to parse a String into an EntityGraph with Hibernate 5.4

JPA 2.1 introduced the annotation-based Named Entity Graphs and the Entity Graph API. They provide query-independent ways to define which entity attributes Hibernate shall fetch from the database. And while you can’t omit eagerly fetched associations or attributes with Hibernate, you can specify a query-specific eager loading for a graph of associations. Sounds great, doesn’t…

How to lazily load non-relational attributes in a portable way
|

How to lazily load non-relational attributes in a portable way

JPA’s @Basic annotation supports a fetch attribute that you can use to define the FetchType of an entity attribute. That seems to be the same approach as you use to define the fetching behavior of an entity association. So, lazy loading of non-relational entity attributes should be easy, right? Well, unfortunately, it isn’t that easy….

5 Common Hibernate Mistakes That Cause Dozens of Unexpected Queries
|

5 Common Hibernate Mistakes That Cause Dozens of Unexpected Queries

If there is one thing that’s often criticized about JPA and Hibernate, it’s that it sometimes execute more queries than you expected. And I’m not talking about 1 or 2 additional queries. I’m talking about dozens or even hundreds of them. The worst thing about it is that you don’t recognize that problem if you…

How to Choose the Most Efficient Data Type for To-Many Associations – Bag vs. List vs. Set

How to Choose the Most Efficient Data Type for To-Many Associations – Bag vs. List vs. Set

Which data type should you use to map a to-many association with Hibernate? Is it better to use a Set or a List? That’s a very common question, and most developers are surprised when they look at the documentation and find out that these are not the only options. You can also use a Bag…