With Hibernate 4, you can use the Integerator spi approach.
Although the sleep mode command suggests using the JPA EntityManager, sometimes you just want to use the good old SessionFactory with JPA annotations.
- Include org.hibernate: hibernate-entitymanager as a dependency (assuming you use maven, pom snippet as follows):
<dependence>
<group id> org.hibernate </ group id>
<artifact> hibernation EntityManager - </ artifact>
<version> 4 * <./ Version>
</ dependency>
- Create an integrator integrator register file /META-INF/services/org.hibernate.integrator.spi.Integrator and register JpaIntegrator to enable JPA event annotations by pasting the following content:
org.hibernate.jpa.event.spi.JpaIntegrator
Ref:
arkuarku.wordpress.com/2014/10/23/spring-hibernate4-enable-jpa-prepersistpreupdate-annotation-using-sessionfactroy/
Cm:
https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
http://in.relation.to/2012/01/09/event-listener-registration/
source share