5 Primary Key Mappings for JPA and Hibernate Every Developer Should Know

5 Primary Key Mappings for JPA and Hibernate Every Developer Should Know

Mapping a primary key column with JPA and Hibernate is simple. You just need to add an attribute to your entity, make sure that its type and name match the database column, annotate it with @Column and you’re done. You can then use the primary key to load the entity, and Hibernate sets the primary…

Localized Data – How to Map It With Hibernate

Localized Data – How to Map It With Hibernate

Internationalization not only affects the UI. If your application stores user-generated data and supports multiple languages, you also need a way to store different translations in your database. Typical examples are: market places that allow you to provide product descriptions in various languages, travel sites that offer trips to people all over the world and…

Best Practices for Many-to-Many Associations with Hibernate and JPA

Best Practices for Many-to-Many Associations with Hibernate and JPA

Many-to-Many associations are one of the most commonly used associations with JPA and Hibernate. You can find lots of examples for them in the real world, and you can map them with JPA and Hibernate as a uni- or bidirectional association in your domain model. But you probably also know that these mappings provide several…

Implementing the Repository pattern with JPA and Hibernate
|

Implementing the Repository pattern with JPA and Hibernate

The repository pattern is extremely popular. In its modern interpretation, it abstracts the data store and enables your business logic to define read and write operations on a logical level. It does that by providing a set of methods to read, persist, update and remove an entity from the underlying data store. Old vs. modern…

Ultimate Guide to Implementing equals() and hashCode() with Hibernate
|

Ultimate Guide to Implementing equals() and hashCode() with Hibernate

The implementation of the equals() and hashCode() methods for entity classes is an often discussed question. Do you really need them? There are lots of applications that work perfectly fine using Java’s default methods provided by the Object class. And if you need to implement them, how should you do that? Should you use all attributes…