Hibernate Tip: Create an EntityGraph with multiple SubGraphs

Hibernate Tip: Create an EntityGraph with multiple SubGraphs

Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please post a comment below. Question: On my tutorial about JPA’s EntityGraphs, Bipin Shrestha asked the following question: “Can you show me an example of…

Why, When and How to Use DTO Projections with JPA and Hibernate
|

Why, When and How to Use DTO Projections with JPA and Hibernate

DTOs are easy to use and the most efficient projection for read-only operations. So, whenever you don’t need to change the requested information, you should prefer a DTO projection. But what exactly is a DTO? How does such a projection work with Hibernate? And how can you use it in your queries? I will answer…

Hibernate Tips: How to Handle NULL Values while Ordering Query Results in a CriteriaQuery
|

Hibernate Tips: How to Handle NULL Values while Ordering Query Results in a CriteriaQuery

Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please post a comment below. Question: You showed in a previous tip how to handle null values in a JPQL ORDER BY clause. Can I…

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…

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…