java - 如何扫描EJB模块中的实体

标签 java jpa ear persistence.xml

我有一个耳朵文件,其结构如下。 [ejb-1.jar] 和 [ejb-2.jar] 都包含 EBJ bean 和实体类。 但是,当我尝试将其部署到服务器时,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 。

根据 JPA 规范第 8.2 节:

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.

关于java - 如何扫描EJB模块中的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49192767/

相关文章:

java - JPA 数组映射

hibernate - 使 JPA EntityManager session 无效

java - Hibernate、JPA - 具有两个表的多对多示例

java - Maven EAR 项目 - JAR 未被排除?

java - EAR 中的差异 部署在 Websphere 应用程序服务器中。 ( war 到耳边)

java - Java中的继承和多态

java - Eclipse:Java:折叠小于方法的代码块

java - unicode字符的编码?

java - start() 方法从 start() 调用线程......令人困惑

java - 部署 Spring .ear 时常量池标记无效