Jboss 7.1 bug configuring JPA through Hibernate
toniortega Jan 9, 2013 6:43 AMHi to everybody!
I'm developing a JPA aplication that uses hibernate direct configuration and when Jboss starts throws an error "Failed to start service" due to a DuplicateMappingException.
It really seems a Jboss bug.
I show a minimalized version of what i have:
In my persistence.xml:
<persistence-unit name="appPersUnit">
<jta-data-source>java:jboss/datasources/ds_mdlw_oracle_ownpres</jta-data-source>
<properties>
<property name="hibernate.ejb.cfgfile" value="/META-INF/hibernate_appPersUnit.cfg.xml"/>
</properties>
</persistence-unit>
In my META-INF/hibernate_appPersUnit.cfg.xml:
<session-factory>
<property name="show_sql">true</property>
<property name="hibernate.default_schema">ownpres</property>
<mapping resource="com/app/midpsp/model/entity/app/MidpspCountryIso.hbm.xml" />
</session-factory>
When I start Jboss in the console & log appears:
11:59:02,740 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.persistenceunit."MID_PSP_EAR.ear/MID_PSP.jar#app": org.jboss.msc.service.StartException in service jboss.persistenceunit."MID_PSP_EAR.ear/MID_PSP.jar#app": Failed to start service
..
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.app.midpsp.model.entity.app.MidpspCountryIso
Note that this is a minimalized version, i have done one persistent unit with one hibernate configuration and only one very simple mapping (coutry iso codes).
I think that the "automatic hibernate deployment processor" is in conflict with JPA definition.
As jboss finds hbm files on the classpath i supose that uses the "hibernate deployment processor" (wich i believe can not be turned off), then, as JPA explicit references the same hbm files, then there is de duplicate mapping error.
I've done a ugly solution, I renamed hbm.xml to hbm_xml and all then worked ok. I believe that jboss doesn't recognize hbm_xml as hibernate mappings and doesn't switch on the "hibernate deployment processor", but, as i've said this is a very ugly solution. Does it exist a better solution?
Thanks in advance!
P.D: I showed the minimized version of my app. The real application uses two persistent unit with same mapping names but different packages, but the problem can be reproduced with this example.