Include @PrePersist and @PreUpdate in Spring

How do I enable the required Spring / JPA / Hibernate behaviors to invoke the @PrePersist and @PreUpdate bindings?

Our stack includes those three and a repository for each object, but we believe that it is better to model this as the possibility of matching the object itself with the help of these interceptors, but they are not called. Each repository has an EntityManager introduced. I use these EntityManager, not sessions.

An EntityManager is created by org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean , which uses org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter and org.springframework.orm.jpa.JpaTransactionManager . There is org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor . factory refers to com.mchange.v2.c3p0.ComboPooledDataSource .

Is it necessary to manually install / connect something (an object listener?) To ensure that calls are made. I can not find the documentation for this.

+4
source share

Source: https://habr.com/ru/post/1215832/


All Articles