4

I get this exception when I try to override the mapping of an entity through the orm.xml file:

2014-11-10T20:08:30.815+0100|Severe: Exception while preparing the app : [PersistenceUnit: irems-main] Unable to build Hibernate SessionFactory
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping testing_ejb.MyAddress
at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2835)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:816)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:199)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:107)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)

You may download the SSCCE from here

It contains nothing more than two projects (EAR + EJB) and a mapped entity managed by a bean. The respective entity is marked with @Entity, and mapped in the orm.xml

Error occurs at deployment.

Georgian
  • 8,795
  • 8
  • 46
  • 87

1 Answers1

0

Change your entity declaration in orm xml as follows:

<entity name="Employee" class="testing_ejb.MyAddress" metadata-complete="false">
</entity>

Also the META-INF/orm.xml must reside next to your persistence.xml configuration file. Move the orm.xml from the child jar to where the root persistence.xml is located.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • Did you test this out? Still doesn't work for me. Does it have anything to do with the placement of the Hibernate suite? 'Cause with GF3 you could choose whether you want Hibernate with it or not. GF4 doesn't have that. – Georgian Nov 17 '14 at 15:10
  • Check my updated answer. I think the orm.xml must be collocated with persistence.xml. – Vlad Mihalcea Nov 17 '14 at 16:52
  • Still no change. Could it be something wrong with my setup? Can you reproduce the problem or not? – Georgian Nov 18 '14 at 14:20
  • I don;t have GC on my current machine, so I can't replicate it. – Vlad Mihalcea Nov 18 '14 at 14:35