Announcement Announcement Module
No announcement yet.
Spring Data MongoDB Cross-Store plugin and JPA PrePersist and PreUpdate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data MongoDB Cross-Store plugin and JPA PrePersist and PreUpdate

    We have an application with the following set up:

    Java 6.0
    Spring Data JPA 1.1.0.RELEASE
    Spring Data MongoDB 1.0.2.RELEASE
    Spring Data MongoDB Cross-Store 1.0.2.RELEASE
    Hibernate JPA 2.0

    We have several classes in this application that use the JPA PrePersist, PreUpdate, PostPersist and PostUpdate annotations. An example is given below.

    public class Person
        private String password;
        public void beforeSave()
                this.password = Security.encrypt(this.password);
    As soon as we turn on AspectJ weaving for the cross-store plugin, the Spring application context fails to load with the error:

    Caused by: javax.persistence.PersistenceException: You can only annotate one callback method with javax.persistence.PrePersist in bean class: org.example.domain.Person
            at org.hibernate.ejb.event.CallbackResolver.resolveCallback(
            at org.hibernate.ejb.event.EntityCallbackHandler.addCallback(
            at org.hibernate.ejb.event.EntityCallbackHandler.add(
            at org.hibernate.ejb.event.JpaIntegrator.integrate(
            at org.hibernate.internal.SessionFactoryImpl.<init>(
            at org.hibernate.cfg.Configuration.buildSessionFactory(
            at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(
            at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(
            at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(
            at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(
            at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.
            at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(
    I have found out that the root cause for the error is that the Aspect MongoDocumentBacking weaves additional PrePersist and PreUpdate methods into entity classes. Since the classes already have methods with these annotations, Hibernate Entity Manager fails to validate these classes.

    Is there any guidance on how the cross-store plugin should be used with applications that have existing code that use JPA annotations?