当我尝试通过orm.xml
文件覆盖实体的映射时,我收到此异常:
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)
它只包含两个项目(EAR + EJB)和一个由bean管理的映射实体。相应的实体标有@Entity
,并映射到orm.xml
部署时出错。
答案 0 :(得分:0)
更改 orm xml 中的实体声明,如下所示:
<entity name="Employee" class="testing_ejb.MyAddress" metadata-complete="false">
</entity>
META-INF / orm.xml也必须位于persistence.xml配置文件旁边。将orm.xml从子jar移动到root persistence.xml所在的位置。