Persistence.xml放在eclipse项目中 [英] Persistence.xml where to put in eclipse project

查看:357
本文介绍了Persistence.xml放在eclipse项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题...

我在Eclipse环境中有几个项目

包含的MainApp(企业应用程序项目)

Simple question...
I have a few projects in Eclipse enviroment
MainApp(Enterprise Application Project) which "includes"


  1. WebController(EJB Project)

  2. WebModel(JPA Project)

  3. WebView Web项目)


问题是在哪里放置persistance.xml文件?


Problem is where to put persistance.xml file?

获取异常:
java.lang.IllegalStateException:无法检索UnitName DataModel的EntityManagerFactory

Getting exception: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName DataModel

推荐答案

8.2节中的 JPA 2.0规范规定了包装的要求。它说

The JPA 2.0 specification in section 8.2 states the requirements for packaging. It says


持久化单元由
persistence.xml文件定义。该文件或
目录,其META-INF目录
包含persistence.xml文件是
,称为持久性
单位的根。

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.

在Java EE环境中,
持久性单元的根目录必须是以下
之一:

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目录

  • EAR库目录中的jar文件

  • 应用程序客户端jar文件

  • 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

不需要将包含持久性单元
的EJB-JAR或
WAR文件打包在EAR中,除非
持久化单元除了在EJB-JAR或WAR中包含
之外,还包含持久性
类。见
8.2.1.6。

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.

如果您认为有必要,可以阅读本章的其余部分。在Eclipse中,这意味着您需要配置项目之间的依赖关系,以确保部署文件被正确打包。您通常在项目 - >属性 - 构建路径中配置项目选项卡。

You can read the rest of the chapter if you deem it necessary. In Eclipse that means that you need to configure the dependencies between your projects to ensure the deployment files are packaged appropriately. You typically configure that in Project->Properties->Build Path in the Projects tab.

但是,我不确定Eclipse是否按照Web服务器部署的要求进行打包。我知道它在EAR项目中。

However, I am not sure if Eclipse packages it up as required for Web server deployment. I know it does in a EAR project.

这篇关于Persistence.xml放在eclipse项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆