如何扫描EJB模块中的Entity

How to scan Entity in EJB module

我有一个结构如下的 ear 文件。 [ejb-1.jar] 和 [ejb-2.jar] 都包含 EBJ bean 和实体 class。 但是,当我尝试将它部署到服务器时,JPA 不会在 ejb jar 文件中扫描我的实体。 谁能告诉我如何配置 persistence.xml 文件?

ear

-- lib (folder)

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

-- ejb-1.jar

-- ejb-2.jar

-- app.war

-- meta-inf (folder)

-------- persisetence.xml

将 persistence.xml 放在每个 EJB jar 文件中的 META-INF 中。

您也可以使用标签指向特定的 jar 持有实体。

根据第 8.2 节 JPA 规范:

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:

  • 一个EJB-JAR文件
  • WAR 文件的 WEB-INF/classes 目录[80]
  • WAR 文件 WEB-INF/lib 目录中的 jar 文件
  • EAR库目录下的一个jar文件
  • 一个应用程序客户端jar文件它不是

    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.