Loading...

Letzte Beiträge

JPA 7. Januar 2021

JPA Doesn't Call Persist But Merge Operation On New Entities

When working with JPA I prefer generating the primary key on the application and not in the database (check out this post from James Brundege ). Additionally, I also prefer optimistic locking and in order to use it you need to specify a @Version field in your Entity. But you need to be careful how to initialize these two fields. In this post I’ll talk about an error when you assign a default value for both fields in JPA which leads the EntityManager to never call persist but the merge operation instead when creating a new entity.


JPA 28. Januar 2020

Additional auditing with Spring Data JPA and Hibernate

Spring Data provides an easy way of keeping track who creates and modifies a persistent entity as well as when the action happened by annotating properties with @CreatedBy, @CreatedDate, @LastModifiedBy and @LastModifiedDate. The properties are automatically provided by an implementation of the AuditAware and DateTimeProvider interface. Beside this common auditing information in my current projects some entities require storing auditing-information about crucial state-changes like soft-deletion. Previously we had to fill the properties ourself:


Top