How to use @PrePersist and @PreUpdate on Embeddable with JPA and Hibernate

Introduction In a previous article, I explained how you could audit entity modifications using the JPA @EntityListeners for embeddable types. Since Hibernate ORM 5.2.17 now allows you to use the @PrePersist and @PreUpdate JPA entity listeners, we can simplify the previous example, as you will see in this article.

How to audit entity modifications using the JPA @EntityListeners, @Embedded, and @Embeddable annotations

Introduction After I wrote the article about inheriting properties from a base class entity using @MappedSuperclass, I got an avalanche of opinions, but this one from Lukas deserves a blog post: While @MappedSuperclass has its benefit, allowing you to reuse even the @Id mapping, as well as being more lenient towards Hibernate-specific auto-generated properties like @GeneratedValue, using Embeddable types is the other JPA alternative for reusing a bunch of properties among multiple entities. In this article, we are going to see how we can reuse several audit-related properties using @Embeddable and another… Read More

Hypersistence Optimizer can automatically detect if you are using JPA and Hibernate properly