This would help:
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM --- ObjectName: persistence.units:unitName=msp-par State: NOTYETINSTALLED Depends On Me:
Not sure why this isn't being deployed?
In fact, only having one Jar but moving the persistence.xml into the Ear META-INF is enough to do this!
Any ideas of how to move the persistence.xml into the Ear properly?!
As far as i know, JBoss does not look in the META-INF folder for the persistence.xml file. The documentation at http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html/entityconfig.html says this:
3.2.2. persistence.xml and .jar files
Entities are placed in a EJB-JAR .jar file or a .jar file all their own. You must also define a persistence.xml file that resides in the META-INF folder of the .jar file.
By the way, why do you want to place the persistence.xml in the META-INF of the EAR file?
Hm I thought I read somewhere it did. It doesn't seem to though!
Basically I have two EJB jars that need to share the same persistence unit, within the same EAR.
Where msp2_ejb.jar is dependent on msp1_ejb.jar
That looks like one ejb is being used as the persistence layer and one as the session-bean layer.
Ours are both mixed in each EJB.
Can you give us a bit more specific example of your case? You mentioned you have 2 ejb jars msp1_ejb.jar and msp2_ejb.jar which are trying to use a the same persistence unit. If i understand your scenario right, you could have something like this:
msp.ear | |--- META-INF | | | |-- application.xml | | |--- mypersistence.jar | | | |--- META-INF | | | | | |--- persistence.xml | | | |--- <entities> | | |--- msp1_ejb.jar | |--- msp2_ejb.jar
And in the EJBs in the msp1_ejb.jar and msp2_ejb.jar, you could inject the persistence context as follows:
@PersistenceContext (unitName="mypersistence.jar#msp-par") private EntityManager manager;
Let us know, if i did not understand your scenario right.
There is no persistence jar as such. It's simply:
msp.ear | |--- META-INF | | | |-- application.xml | | |--- msp1_ejb.jar | |--- msp2_ejb.jar |
And I need to know where to put the persistence.xml file and get msp2_ejb.jar talking to msp1_ejb.jar EJBs using the same persistence unit name.
Are your "entities" present in both the ejb jar files? Or are they in a single ejb jar file (in which case, you can place the persistence.xml in the META-INF folder of that ejb jar). And if you are having the entities spread across these 2 ejb jars, is there any specific reason for doing so?
There are entities in both jar files, but they are not replicated.
The reason to do so is to have a common EJB jar that contains commonly used EJBs in different applications...
Okay in that case, probably you can place the persistence.xml in the META-INF folder of any one of the ejb jars. Let's assume you placed it in msp1_ejb.jar. The persistence.xml can then contain this:
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="msp-par"> <jta-data-source>java:/@deployeddatabase@</jta-data-source> <jar-file>../</jar-file> <jar-file>../../msp2_ejb.jar</jar-file> <properties> <property name="hibernate.hbm2ddl.auto" value="false"/> <property name="com.intellij.javaee.persistence.datasource" value="Datasource"/> </properties> </persistence-unit> </persistence>
This way both the ejb jar files will be scanned for the entities. I tried this scenario on my local setup of JBoss-4.2.2 and this seems to be working. It picked up the entities that were spread across (and not replicated) the 2 ejb jars. Try it out and see if it works for you.
hum... good topic!
let me ask a question:
the persistence.xml has the information about the persistence driver (if it should use Postgresql or Oracle, for example)
but, if I put this information inside persistence.xml, if I change the database, I will have to recompile the jars with the correct persistence.xml
is there a workaround to avoid recompiling the jar?
thanks in advance
I would advice to try it. It have to be possible, to change the old persistence.xml to the new persistence.xml. Since your ejb tries to connect to the database or uses an entity-manager, I think the persistence-context will be refreshed. It should be similar like patching new compiled java-classes.
I hope it so.