Hibernate event listeners for JPA callbacks

前端 未结 2 1115
忘了有多久
忘了有多久 2020-12-21 00:45

How can I enable the Hibernate event listeners, that handle JPA callbacks?

Currently I am using using Hibernate 4 with SessionFactory configuration, but JPA callback

相关标签:
2条回答
  • 2020-12-21 01:05

    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.

    0 讨论(0)
  • 2020-12-21 01:10

    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.

    0 讨论(0)
提交回复
热议问题