3 Replies Latest reply on Jul 15, 2012 3:03 PM by Adam Warski

    Caused by: org.hibernate.MappingException: @AuditMappedBy points to a property that doesn't exist: com.dna.bifincan.model.user.UserInvitation.inviter

    hantsy bai Master

      I only want to audit the User class but ignore all relations.

       

      the original version the related codes is the following:

       

      @Entity

      //@Audited(targetAuditMode= RelationTargetAuditMode.NOT_AUDITED)

      @Table(name = "user", uniqueConstraints = {

          @UniqueConstraint(name = "UQ_gsmPrefix_gsmNumber", columnNames = {"gsm_prefix", "gsm_number"}),

          @UniqueConstraint(name = "UQ_email", columnNames = "email"),

          @UniqueConstraint(name = "UQ_username", columnNames = "username")})

      @NamedQueries({

          @NamedQuery(name = "User.findByUsername", query = "select u from User u where u.username=:username"),

          @NamedQuery(name = "User.findByEmail", query = "select u from User u where u.email=:email")})

      @Access(AccessType.FIELD)

      public class User extends com.dna.bifincan.model.BaseEntity{

       

       

       

      // @AuditMappedBy(mappedBy="inviter", positionMappedBy="position")

          @OneToMany( cascade = CascadeType.ALL, mappedBy="inviter")

      //   @JoinColumn(name = "invited_by", nullable = false)

      //   @IndexColumn(name="position", columnDefinition="bigint")

          private List<UserInvitation> sentInvitations = new ArrayList<UserInvitation>();

      }

       

       

      @Entity

      @Table(name = "user_invitation", uniqueConstraints = @UniqueConstraint(name = "UQ_user_email", columnNames = {

          "invited_by", "email" }))

      @NamedQueries({

          @NamedQuery(name = "UserInvitation.findByInviterAndEmail", query = "select i from UserInvitation i where i.inviter=:inviter and i.email=:email"),

          @NamedQuery(name = "UserInvitation.findByEmailAndOptedOut", query = "select i from UserInvitation i where  i.email=:email and i.optedOut=true") })

      public class UserInvitation extends com.dna.bifincan.model.BaseEntity

       

       

        // bi-directional many-to-one association to User

          @ManyToOne

          @JoinColumn(name = "invited_by", nullable = false , updatable=false, insertable=false)

          private User inviter;

       

       

       

       

       

      I changed to use the  Envers...

       

      @Entity
      @Table(name = "user_invitation", uniqueConstraints = @UniqueConstraint(name = "UQ_user_email", columnNames = {
          "invited_by", "email" }))
      @NamedQueries({
          @NamedQuery(name = "UserInvitation.findByInviterAndEmail", query = "select i from UserInvitation i where i.inviter=:inviter and i.email=:email"),
          @NamedQuery(name = "UserInvitation.findByEmailAndOptedOut", query = "select i from UserInvitation i where  i.email=:email and i.optedOut=true") })
      public class UserInvitation extends com.dna.bifincan.model.BaseEntity
      
      
        // bi-directional many-to-one association to User
          @ManyToOne
          @JoinColumn(name = "invited_by", nullable = false, updatable=false, insertable=false)
          private User inviter;
      
      

       

       

       

      @Entity
      @Audited(targetAuditMode= RelationTargetAuditMode.NOT_AUDITED)
      @Table(name = "user", uniqueConstraints = {
          @UniqueConstraint(name = "UQ_gsmPrefix_gsmNumber", columnNames = {"gsm_prefix", "gsm_number"}),
          @UniqueConstraint(name = "UQ_email", columnNames = "email"),
          @UniqueConstraint(name = "UQ_username", columnNames = "username")})
      @NamedQueries({
          @NamedQuery(name = "User.findByUsername", query = "select u from User u where u.username=:username"),
          @NamedQuery(name = "User.findByEmail", query = "select u from User u where u.email=:email")})
      @Access(AccessType.FIELD)
      public class User extends com.dna.bifincan.model.BaseEntity
      
      
      

      // bi-directional many-to-one association to UserInvitation

      @AuditMappedBy(mappedBy="inviter", positionMappedBy="position")

      @OneToMany( cascade = CascadeType.ALL)

      @JoinColumn(name = "invited_by", nullable = false)

      @IndexColumn(name="position", columnDefinition="bigint")

      private List<UserInvitation> sentInvitations = new ArrayList<UserInvitation>();
      
      
      

       

       

      I tried several approaches, still got the exception.

       

       

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [jar:file:/E:/MyWorks/bifincan/project/bifincan-website/target/fi/WEB-INF/lib/bifincan-library-1.0-SNAPSHOT.jar!/common/data-access.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: bifincan] Unable to build EntityManagerFactory

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

          at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728)

          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)

          at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)

          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)

          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)

          at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)

          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

          at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)

          at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)

          at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)

          at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)

          at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:530)

          at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1471)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:601)

          at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)

          at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)

          at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)

          at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1436)

          at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:856)

          at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:353)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

          at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)

          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)

          at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)

          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)

          at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

          at java.lang.Thread.run(Thread.java:722)

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [jar:file:/E:/MyWorks/bifincan/project/bifincan-website/target/fi/WEB-INF/lib/bifincan-library-1.0-SNAPSHOT.jar!/common/data-access.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: bifincan] Unable to build EntityManagerFactory

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:400)

          at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275)

          at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)

          at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)

          at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70)

          at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:103)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

          ... 50 more

      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: bifincan] Unable to build EntityManagerFactory

          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)

          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)

          at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)

          at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)

          at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)

          ... 65 more

      Caused by: org.hibernate.MappingException: @AuditMappedBy points to a property that doesn't exist: com.dna.bifincan.model.user.UserInvitation.inviter

          at org.hibernate.envers.configuration.ClassesAuditingData.forcePropertyInsertable(ClassesAuditingData.java:84)

          at org.hibernate.envers.configuration.ClassesAuditingData.updateCalculatedFields(ClassesAuditingData.java:70)

          at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:85)

          at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:113)

          at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:165)

          at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:64)

          at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)

          at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)

          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)

          ... 71 more

       

       

      Any idea, here? Thanks.