Hibernate event listeners for JPA callbacks

烈酒焚心 提交于 2019-11-29 14:12:35
meskobalazs

This question basically asked the same.

So it turns out, that these JPA entity listener annotations are only working when you are using EntityManager in Hibernate (which is understandable). So if you want to use these annotations, you should ditch SessionFactory, and use the JPA-complaint EntityManager or EntityManagerFactory.

I also recommend this approach, because if you are trying to use JPA annotations, it is logical to go for a pure JPA solution, without tying yourself to a Hibernate-specific solution - i.e. SessionFactory.

Add a file named org.hibernate.integrator.spi.Integrator containing a single line

org.hibernate.jpa.event.spi.JpaIntegrator

in your META-INF/services folder. This will enable JPA lifecycle annotations including @EntityListeners for sessionFactory based configurations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!