是否可以为EJB jar定义默认的persistence-context-ref?

时间:2011-08-11 09:06:52

标签: java-ee persistence ejb ear

我有一个我定义的EAR项目

  • 只包含我想要保留的实体的“持久性”JAR(和persistence.xml)
  • 包含活动组件的EJB Jar

在EAR中部署这些组件(使用maven插件构建)时,我总是得到

  

org.glassfish.deployment.common.DeploymentException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [base-entities] in the scope of the module called [ear-0.0.1-SNAPSHOT#ejbs-0.0.1-SNAPSHOT.jar]. Please verify your application.

我该如何解决?我首先考虑为整个EJB jar定义persistence-context-ref(在ejb-jar.xml中),但似乎不可能。那么,我应该写一个辅助persistence.xml链接到第一个吗?

1 个答案:

答案 0 :(得分:0)

尽管看起来很愚蠢(之后),但对这个问题最简单的解决方案是在EJB jar中放入一个复制初始的persistence.xml。实际上,根据我的理解,EAR将从EJB模块(而不是JAR)加载持久性元素。因此,EJB模块必须定义persistence.xml配置文件。

相关问题