-
1. Re: How to make persistence unit visible for other deployments (not EAR)
gonne Aug 25, 2011 7:53 AM (in response to mglowacki)Hi,
I am not sure if it is possible, but you can try to define a dependency from your other deployments to your EntityBeans.jar by providing a manifest (according to https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7) with the following entry:
{code}
Dependencies: deployment.EntityBeans.jar
{code}
Regards,
Gonne
-
2. Re: How to make persistence unit visible for other deployments (not EAR)
mglowacki Aug 25, 2011 8:21 AM (in response to gonne)I did that, but in the documentation I see that "By default items in META-INF of a dependency are not accessible". There is an option "services" that allows to access services directory in META-INF, but not persistence.xml
I added to my persistence.xml those lines:
<property name="jboss.entity.manager.jndi.name" value="java:jboss/MyPU"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/MyPUManagerFactory" />
and tried various combinations of unitName in my sessionbeans.jar class:
@PersistenceContext(unitName="java:jboss/MyPU")
But this also does not help :/
-
3. Re: How to make persistence unit visible for other deployments (not EAR)
smarlow Aug 25, 2011 9:51 AM (in response to mglowacki)Forget about using a java:jboss/MyPU name, just use a scoped reference to the pu (either local or fully application qualified).
Here is an example unit test that shows a local application reference to a pu ("../lib/lib.jar#mainPu"). https://github.com/jbossas/jboss-as/blob/master/testsuite/integration/src/test/java/org/jboss/as/testsuite/integration/jpa/packaging/LibPersistenceUnitBean.java
-
4. Re: How to make persistence unit visible for other deployments (not EAR)
mglowacki Sep 1, 2011 5:28 AM (in response to smarlow)I did not work for me :/
My dirs structure under 'deployments' is:
/EntityBeans.jar/META-INF/persistance.xml
/MyApp.war
and I tried in my class:
public static javax.persistence.EntityManagerFactory emf =
Persistence.createEntityManagerFactory(
"../../EntityBeans.jar#MyPU");
../../EntityBeans.jar#MyPU, ../EntityBeans.jar#MyPU, EntityBeans.jar#MyPU - nothing works.
Now I found in JBoss AS 7 management console, Container/ naming/ java:jboss:
MyPUManagerFactory EntityManagerFactoryImpl@32d959b So actually it is visible outside EntityBeans.jar, right? However I can't access it any way
-
5. Re: How to make persistence unit visible for other deployments (not EAR)
smarlow Sep 1, 2011 10:08 AM (in response to mglowacki)Just as a FYI, it may be helpful to enable JPA TRACE logging, which shows more information about the persistence unit search (output will be in as/standalone/log/server.log. See https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide for example of enabling TRACE.
Having said that and reviewing the responsible code (https://github.com/jbossas/jboss-as/blob/master/jpa/core/src/main/java/org/jboss/as/jpa/container/PersistenceUnitSearch.java), I don't think we can currently reference the PU from a separate application deployment. You could create a jira for that, if you like.
Going back to your other earlier attempt, maybe you just need to change how your looking up the EntityManagerFactory to use JNDI instead of injection. Maybe try something like this:
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/MyPUManagerFactory" />
.
.
.
EntityManagerFactory em = (EntityManagerFactory) initialCtx.lookup("java:jboss/MyPUManagerFactory");
-
6. Re: How to make persistence unit visible for other deployments (not EAR)
muthukumaran_m Dec 28, 2012 12:50 PM (in response to smarlow)Hello Scott,
I tried the JNDI approach and it leads me to another issue, let me explain
- I have an entity jar which registers the JNDI for the persistence unit (in the same way as you have suggested), this jar is deployed directly in to the deployment folder as we have multiple WARs using this persistence unit
- I have another WAR in which I lookup the JNDI from the entity jar, I do have the entity jar defined as a dependency in the WARs jboss-deployment-structure.xml
With this said what is happening is, my WAR deploys first and starts looking up the JNDI before even the jar is complete deployed and finished registering in the JNDI.
If I start the server with only the persistence unit and wait for the server to start and then deploy the WAR it works fine, but if I have both the jar & WAR in place and try to start the server it get the "NameNotFoundException"
Can you please suggest a solution for this?
Thanks,
Muthu