0 Replies Latest reply on Nov 28, 2014 9:39 AM by Simon Martinelli

    Envers and hbm.xml

    Simon Martinelli Novice

      Hi,

       

      We are trying to use Envers with hbm.xml mapping files but we have a problem on a one-to-many relationship:

       

      1. java.lang.ExceptionInInitializerError

      at com.prodega.dao.EnversTest.init(EnversTest.java:21)

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

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

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

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

      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

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

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

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

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

      at org.eclipse.jdt.internal.launching.LongCommandLineLauncher.main(LongCommandLineLauncher.java:43)

      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: ProdegaJpa-test] Unable to build EntityManagerFactory

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

      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)

      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)

      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)

      at com.prodega.test.util.EjbTestContext.<clinit>(EjbTestContext.java:23)

      ... 21 more

      Caused by: org.hibernate.HibernateException: could not init listeners

      at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)

      at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:2010)

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

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

      ... 25 more

      Caused by: org.hibernate.MappingException: Unable to read the mapped by attribute for subs in com.prodega.model.envers.ASubEntity!

      at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.getMappedBy(CollectionMetadataGenerator.java:575)

      at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.addOneToManyAttached(CollectionMetadataGenerator.java:174)

      at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.addCollection(CollectionMetadataGenerator.java:157)

      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addValue(AuditMetadataGenerator.java:204)

      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addProperties(AuditMetadataGenerator.java:223)

      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateSecondPass(AuditMetadataGenerator.java:484)

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

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

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

      at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:337)

      at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)

      at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)

      at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)

      ... 28 more

       

      It seams that the mapped by attribute is missing but hbm.xml does not have such an attribute. We just can define inverse=true

       

      Any help is appreciated.

       

      Kind regads,

      Simon