0

Possible Duplicate:
Sharing a persistence unit across components in a .ear file

I have a project with JPA entities and a persistence.xml file. I packaged them into a jar file and deployed to an app server (JBoss 7.1).

I have another project, a web application, which has a session bean and I'd like to use this persistence unit there (by injection).

However I get an exception:

Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011047: Component class com.mypackage.MyService for component MyService has errors: 
JBAS011440: Can't find a persistence unit named my_pu in deployment "mywebapp.war"

I tried to add the jar of the PU as dependency in the manifest.mf of the war but without any success.

Do you know how to achieve this?

Community
  • 1
  • 1
Balázs Németh
  • 6,222
  • 9
  • 45
  • 60
  • Are these separately deployed artefacts, or is the JAR a library? – David Grant Oct 03 '12 at 13:32
  • I'd like to deploy them separately. – Balázs Németh Oct 03 '12 at 13:38
  • They should be independent. Imagine deploying a WAR file on the same app server and accidentally using someone else's PU. :( – David Grant Oct 03 '12 at 13:41
  • Actually, that's the ultimate goal: to share the PU across multiple web apps. Do I have to build an EAR then? – Balázs Németh Oct 03 '12 at 13:43
  • See http://stackoverflow.com/questions/4073635/sharing-a-persistence-unit-across-components-in-a-ear-file – David Grant Oct 03 '12 at 13:45
  • I've seen this but I'm not sure I completely understand. Especially this part: "A persistence unit that is defined at the level of an EJB-JAR, WAR, or application client jar is scoped to that EJB-JAR, WAR, or application jar respectively and is visible to the components defined in that jar or war." What does visible to the components defined in that jar mean? Its classes? Or I might define another application (jar, war) there to make the PU visible for them? I assume not but for me it's ambiguous. – Balázs Németh Oct 03 '12 at 13:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17511/discussion-between-david-grant-and-balazs-maria-nemeth) – David Grant Oct 03 '12 at 14:08

1 Answers1

1

One option is to go with JBoss modules, but we don't have a straightforward approach to achieve JPA. Refer the issue in JBoss community. The other option is to go with OSGI to achieve this.