【问题标题】:How to combine several jar files with peristence.xml files into one jsf project如何将多个jar文件与peristence.xml文件合并到一个jsf项目中
【发布时间】:2014-07-12 05:05:51
【问题描述】:

我开发了几个 jar 文件(tasks.jar、calendar.jar、user.jar、authentication.jar),其中每个文件都包含 persistence.xml 文件。所有这些 persistence.xml 文件都具有相同的持久性单元名称,例如“TASK_MANAGER”。
我的问题是我能否将这些 jar 文件添加到 JSF Web 项目的 lib 文件夹中,并通过托管会话 bean 使用它们,该 bean 再次使用 JPA 实体管理器,持久性单元名称为“TASK_MANAGER”。例如:

//All the imports go here (import com.app.model.task) etc....
@ManagedBean     
@RequestScoped  
public class TaskController{
  //Access the entity manager and work with their methods here
}

我知道http://docs.oracle.com/javaee/6/tutorial/doc/bnbqw.html

如果您将持久性单元打包在一个 JAR 文件中, 包含在 WAR 或 EAR 文件中,JAR 文件应位于 要么

  • WAR 的 WEB-INF/lib 目录
  • EAR 文件的库目录

但我的问题是我可以使用多个persistence.xml 文件来做到这一点。

因为在 Eclipse 中,当我尝试实现这一点时,只加载了最终的 jar 文件的持久性文件,我知道这是因为当我尝试运行应用程序时无法识别其他实体。

如何在一个项目中包含多个 persistence.xml 文件。

我已经检查了这些 Configure persistence units to be available in several jars of an earhttps://stackoverflow.com/questions/23398636/combining-entities-across-jars-in-a-single-persistence-xml-file

【问题讨论】:

    标签: jsf jpa eclipse-kepler persistence.xml


    【解决方案1】:

    解决方案非常简单。 eclipselink 想知道子项目的persistence.xml 文件是什么。因此,在那些开发 JAR 的迷你项目中,我不得不将以下属性添加到它们的 persistence.xml 文件中。

    <property name="eclipselink.composite-unit.member" value="true"/>
    

    之后,在主 persistence.xml 文件中,您还必须设置以下属性。

    <property name="eclipselink.composite-unit" value="true"/>
    

    现在一切正常..

    【讨论】:

      猜你喜欢
      • 2011-07-02
      • 2013-09-30
      • 2013-08-28
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多