Enable @PrePersist and @PreUpdate in Spring

对着背影说爱祢 提交于 2019-12-10 08:23:11

问题


How does one turn on the required Spring / JPA / Hibernate behaviours to invoke @PrePersist and @PreUpdate hooks?

Our stack includes those three and a Repository for each entity, but we feel it is better to model this as a resposibility of the entity itself with the help of these hooks, but they are not called. Each Repository has an EntityManager injected. I am using those EntityManagers, not Sessions.

The EntityManager is created by a org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean which uses the org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter and org.springframework.orm.jpa.JpaTransactionManager. There is a org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor present. The factory references a com.mchange.v2.c3p0.ComboPooledDataSource.

Is it necessary to manually install / wire the something in (an entity listener?) to ensure the calls are made. I cannot locate any documentation for this.

来源:https://stackoverflow.com/questions/14458473/enable-prepersist-and-preupdate-in-spring

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