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 Apply DISTINCT to Your JPQL But Not Your SQL Query

Hibernate Tips: How To Apply DISTINCT to Your JPQL But Not Your SQL Query

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: I’m using a query with a JOIN FETCH clause to load parent entities with all their child entities. The JPQL…

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…

Hibernate Tips: How to Call a Function that returns a SYS_REFCURSOR
|

Hibernate Tips: How to Call a Function that returns a SYS_REFCURSOR

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 leave a comment below. Question: We are using an Oracle database, and I need to call a function that returns an SYS_REFCURSOR. I tried…