|

Implement your primary key as a Record using an IdClass

There are various reasons to implement your own primary key representation. Your primary key may consist of multiple attributes. Or you’re following domain-driven design principles and want to use a custom type to add semantic meaning to it. Implementing a record and mapping it as an IdClass seems evident in these situations. A record is efficient, easy to implement, immutable…

How to generate DAOs and queries with Hibernate
|

How to generate DAOs and queries with Hibernate

Executing a query with Hibernate requires several lines of repetitive boilerplate code, and many developers have complained about that for years. You have to instantiate a Query object and set all bind parameter values before you can finally execute the query. Since version 6.3.1, Hibernate has solved this with an improved metamodel generator that provides…

11 JPA and Hibernate query hints every developer should know
| |

11 JPA and Hibernate query hints every developer should know

JPA and Hibernate support a set of hints that you can use to provide additional information to your persistence provider to influence the execution of a query. You can use them for lots of different things, like setting a timeout for your query, using an entity graph, or defining the caching of a query result….

Inheritance Strategies with JPA and Hibernate – The Complete Guide
|

Inheritance Strategies with JPA and Hibernate – The Complete Guide

Inheritance is one of the key concepts in Java. So, it’s no surprise that most developers want to use it in their domain model. Unfortunately, the relational table model doesn’t know this concept. So, Hibernate, or any other JPA implementation, has to apply a mapping strategy to map your inheritance hierarchy to one or more…