I have a JPA @Entity class that has been using @PrePersist for quite some time. Today I wanted to add some features where I need the identifier of this object. This identifier is created when HIBERNATE_SEQUENCE is stored in the database. It is usually installed after em.persist (entity).
For some unknown reason, the @PrePersist method starts ... until @PostPersist just fires:
@Entity public class MyEntity { @PrePersist protected void onCreate() { System.out.println("ExtendedEntity.onCreate()"); } @PostPersist protected void afterCreate() { System.out.println("ExtendedEntity.afterCreate()"); } }
I am using JBoss v4.2 with Java v7 +, Hibernate v3.3.1.GA and Seam v2.2.2.Final ...
Are there any hidden requirements to run @PostPersist?
java hibernate jpa
Daniel Bleisteiner
source share