The Best Mapping for Shared Technical Attributes With Hibernate

The Best Mapping for Shared Technical Attributes With Hibernate

Most domain models have a few technical attributes shared by most entity classes. Typical examples are the version attribute and the timestamp or user who performed the last update or persisted an entity. In these situations, many developers ask themselves what’s the best way to model these attributes. Oleg did the same recently in the…

Mixing Inheritance Mapping Strategies with Hibernate

Mixing Inheritance Mapping Strategies with Hibernate

Inheritance is one of the key concepts in Java, and most development teams prefer using it in their domain model. Unfortunately, relational table models don’t support the concept of inheritance. The JPA specification defines multiple mapping strategies to bridge the gap between the object-oriented and the relational world. I explained them in great detail in…

Implementing Bulk Updates with Spring Data JPA

Implementing Bulk Updates with Spring Data JPA

When using Spring Data JPA, most developers are used to letting Spring handle almost all database operations. That’s especially the case for all update operations. Thanks to JPA’s entity mappings and the managed lifecycle of all entity objects, you only need to change an attribute of an entity object. Everything else happens automatically. But having…

Spring Data JPA – Publishing Domain Events When Changing an Entity

Spring Data JPA – Publishing Domain Events When Changing an Entity

Since Spring Data JPA 1.11 (the Ingalls release), you can automatically publish domain events when an entity object gets saved. You only need to add a method to your entity class that returns a Collection of the event objects you want to publish and annotate the method with @DomainEvents. Spring Data JPA calls that method and publishes the events…