0

I have project with two ejb-jars located in [WAR]/WEB-INF/lib. Both ejb-jars uses JPA and contains classes annotated @Entity. But I have problems with packaging and deployment (Glassfish 4). If both of my jars contains persistence.xml then I get following Exception on delpoyment

java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [...] in the scope of the module called [...]. Please verify your application.

I've put persistence.xml in WAR/META-INF and delete persistence.xml from ejb-jars. Deployment is successful, but I get Exception in runtime

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Problem compiling [SELECT ...]. [14, 18] The abstract schema type 'MyClass' is unknown.

MyClass is @Entity class from one of ejb-jars. I think problem is missing persistence.xml in this ejb-jar.

Finally I've try to put persistence.xml in WAR and in ejb-jars, but again I get

java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [...] in the scope of the module called [...]. Please verify your application.

What is a proper place to put persistence.xml and what is a proper way to package such application?

Joel
  • 473
  • 2
  • 7
  • 22

1 Answers1

0

Try to extract all your entities from both ejb projects and persistence.xml to the simple jar file and put that jar file to WEB-INF/lib (I didin't used that config, so it might not work, for sure it would work in case of EAR packaging - meaning EAR, with 3 modules, web and 2 ejbs, and entity jar in ear/lib folder).

Gas
  • 17,601
  • 4
  • 46
  • 93
  • It works that way, when everything in one jar. I'm novice at Java EE, so it seems easier to me to put ejb-jars in [war]WEB-INF/lib. I don't have thorough understanding of packaging in ear. If I package in ear, then can I see classes from one ejb-jar inside another ejb-jar? – Joel Oct 21 '14 at 19:53