-
1. Re: Single persistence.xml file with multiple EJB jars
deanouk Mar 27, 2008 8:08 AM (in response to deanouk)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? -
2. Re: Single persistence.xml file with multiple EJB jars
deanouk Mar 27, 2008 9:40 AM (in response to deanouk)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?! -
3. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 27, 2008 10:36 AM (in response to deanouk)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. -
4. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 27, 2008 10:37 AM (in response to deanouk)By the way, why do you want to place the persistence.xml in the META-INF of the EAR file?
-
5. Re: Single persistence.xml file with multiple EJB jars
deanouk Mar 27, 2008 11:19 AM (in response to deanouk)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.
i.e.
msp.ear
----msp1_ejb.jar
----msp2_ejb.jar
Where msp2_ejb.jar is dependent on msp1_ejb.jar -
6. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 27, 2008 11:27 AM (in response to deanouk)Is this http://www.jboss.com/index.html?module=bb&op=viewtopic&t=131420 of any help?
-
7. Re: Single persistence.xml file with multiple EJB jars
deanouk Mar 27, 2008 11:39 AM (in response to deanouk)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. -
8. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 27, 2008 11:49 AM (in response to deanouk)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. -
9. Re: Single persistence.xml file with multiple EJB jars
deanouk Mar 27, 2008 11:56 AM (in response to deanouk)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. -
10. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 27, 2008 12:01 PM (in response to deanouk)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?
-
11. Re: Single persistence.xml file with multiple EJB jars
deanouk Mar 27, 2008 12:03 PM (in response to deanouk)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... -
12. Re: Single persistence.xml file with multiple EJB jars
jaikiran Mar 27, 2008 12:46 PM (in response to deanouk)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.
-
13. Re: Single persistence.xml file with multiple EJB jars
rruppel Mar 27, 2008 3:51 PM (in response to deanouk)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 -
14. Re: Single persistence.xml file with multiple EJB jars
alex.x Mar 28, 2008 8:48 AM (in response to deanouk)Hi,
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.