Reputation: 333
I am working on a project that uses a very old version of Jboss (4.0.5 - JDK 1.5). Due to time/budget constraints, I cant change this.
My app is deployed as a single EAR file. Within the ear, there is a JAR file that provides basic entity management. Call it jpa-old.jar
. That JAR file contains a persistnce.xml that defines a PU called OldPersist
as follows:
<persistence version="1.0" >
<persistence-unit name="OldPersist">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MySqlDS</jta-data-source>
<class>com.oldjpa.OldEntity1</class>
<class>com.oldjpa.OldEntity2</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
The jar provides the entities themselves along with some access EJBs for CRUD operations. The EntityManger is injected into the EJBs with @PersistenceContext(unitName = "OldPersist")
For various reasons, its no longer desirable to maintain the old entity jar (poor design, code bloat). Therefore I would like to create a new entity access layer. Right now, it will provide access to only new entities via EJBs but over time the old code will be ported to the new JAR. Both have to work simultaneously.
So I create a new JAR (jpa-new.jar
) with the same structure as my old, that defines a new PU, NewPersist
with this persistnce.xml
<persistence version="1.0" >
<persistence-unit name="NewPersist">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MySqlDS</jta-data-source>
<class>com.newjpa.NewEntity1</class>
<class>com.newjpa.NewEntity2</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
Note there is no cross management of entities between the two PUs.
I then create some new EJBs in the new JAR and inject the EM with @PersistenceContext(unitName = "NewPersist")
At deployment time, I get this error:
WARN [org.jboss.system.ServiceController] Problem starting service persistence.units:ear=MyEar.ear,unitName=jpa-new.jar org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.oldjpa.OldEntity1 references an unknown entity:com.oldjpa.OldEntity2
Hibernate is complaining about the new PU - with regard to entities that should be managed by the old PU.
I have tried each JAR in isolation, and they both work fine.
I have tried adding <jar-file>
to the persistnce.xml, but jboss then complains it cant find the JAR on deployment (its suppose to be a relative path, but relative to what?).
I have tried adding a shared persistnce.xml to the EARs META-INF. That doesnt give the same error, but then the EJBs within each JAR file complain they cant find their PUs.
So my question is, is this configuration supported (multiple jars each with their own persistnce.xml) and if so, how do I get it to work?
Many thanks
Upvotes: 0
Views: 404
Reputation: 139
Why don't you create a single persistence.xml with 2 persistence units in them?
Upvotes: 1