1

I have an ear file with structure below. [ejb-1.jar] and [ejb-2.jar] is both contain EBJ bean and Entity class. However, when I try to deploy it to server, JPA does not scan my entity in ejb jar file. Can any one tell me how to config persistence.xml file?

ear

-- lib (folder)

-------- log4j.jar (ex)

-- ejb-1.jar

-- ejb-2.jar

-- app.war

-- meta-inf (folder)

-------- persisetence.xml

Community
  • 1
  • 1
Quang Duy
  • 23
  • 3

1 Answers1

0

Place the persistence.xml in the META-INF inside each EJB jar file.

Also you can uyse tag to point to specific jars holding entities.

according to section 8.2 JPA specification:

Within Java EE environments, an EJB-JAR, WAR, EAR, or application client JAR can define a persistence unit. Any number of persistence units may be defined within these scopes. A persistence unit may be packaged within one or more jar files contained within a WAR or EAR, as a set of classes within an EJB-JAR file or in the WAR classes directory, or as a combination of these as defined below. A persistence unit is defined by a persistence.xml file. The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit. In Java EE environments, the root of a persistence unit must be one of the following:

  • an EJB-JAR file
  • the WEB-INF/classes directory of a WAR file[80]
  • a jar file in the WEB-INF/lib directory of a WAR file
  • a jar file in the EAR library directory
  • an application client jar file It is not

    required that an EJB-JAR or WAR file containing a persistence unit be packaged in an EAR unless the persistence unit contains persistence classes in addition to those contained within the EJB-JAR or WAR. See Section 8.2.1.6.

Alexander Petrov
  • 9,204
  • 31
  • 70
  • Thanks. I'm checking document but do I need to list up all class in persistence.xml? And is there any problem if I have a [ejb-3.jar] which will use entity of [ejb-2.jar]? – Quang Duy Mar 09 '18 at 11:58
  • @QuangDuy if you want cross references you will have to use https://stackoverflow.com/questions/4433341/what-is-the-right-path-to-refer-a-jar-file-in-jpa-persistence-xml-in-a-web-app – Alexander Petrov Mar 09 '18 at 12:02
  • Thanks, I'm trying to move persistence.xml into [ejb-persistence.jar]. And then add [ejb-1.jar] and [ejb-2.jar] to persitence by using . It working rightnow :) – Quang Duy Mar 09 '18 at 12:17