使用SessionFactory配置Hibernate 4.3以使用@PrePersist
我正在尝试通过此博客步骤进行操作.
I am trying do it throught this blog steps.
http://leakfromjavaheap.blogspot. com.es/2013/08/prepersist-and-preupdate-not-working.html
但是从Hibernate 4.3开始,将删除hibernate-entitymanager.jar中的事件包.
But starting from Hibernate 4.3, events package in hibernate-entitymanager.jar are removed.
另一方面,我一直在阅读有关拦截器和事件的信息. http://docs.jboss.org/hibernate/orm/4.3/manual/zh-CN/html_single/#events
In another hand, I had been reading about interceptors and events. http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#events
这仅仅是实现@PrePersist行为的两种方法吗?还是可以在SessionFactory中使用@EntityListeners批注?尽管我希望赢得@PrePersist注释兼容性.
Are this only two ways to implement @PrePersist behaviour? or could use @EntityListeners annotation with SessionFactory?. Although I would prefer win @PrePersist annotation compatibility.
谢谢.
对于Hibernate 4,您可以使用Integerator spi方法.
With Hibernate 4, you can use Integerator spi approach.
尽管休眠团队建议使用JPA EntityManager,但有时您只想继续使用带有JPA批注的旧式SessionFactory.
Although the hibernate team suggest to use JPA EntityManager, but sometime you just want to keep using the good old SessionFactory with JPA annotations.
- 包括org.hibernate:hibernate-entitymanager作为依赖项(假设您正在使用maven和pom片段,如下所示):
- Include org.hibernate:hibernate-entitymanager as dependency (assuming you are using maven, pom snippet as follows):
<依赖性>
< groupId> org.hibernate</groupId>
< artifactId>休眠实体管理器</artifactId>
< version> 4.*</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.*</version>
</dependency>
org.hibernate.jpa.event.spi.JpaIntegrator
org.hibernate.jpa.event.spi.JpaIntegrator
参考:
arkuarku.wordpress.com/2014/10/23/spring-hibernate4-enable-jpa-prepersistpreupdate-annotation-using-session-factroy/
参见:
https://docs.oracle.com/javase/tutorial/sound/SPI -intro.html
http://in.relation.to/2012/01/09/event-listener-registration/
Ref:
arkuarku.wordpress.com/2014/10/23/spring-hibernate4-enable-jpa-prepersistpreupdate-annotation-using-sessionfactroy/
See:
https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
http://in.relation.to/2012/01/09/event-listener-registration/