Persistence.xml放在eclipse项目的哪里
简单的问题...
我在 Eclipse 环境中有一些项目
MainApp(企业应用程序项目)其中“包含”
- WebController(EJB 项目)
- WebModel(JPA 项目)
- WebView(动态 Web 项目)
问题是把 persistance.xml 文件放在哪里?
获取异常: java.lang.IllegalStateException:无法检索unitName DataModel的EntityManagerFactory
Simple question...
I have a few projects in Eclipse enviroment
MainApp(Enterprise Application Project) which "includes"
- WebController (EJB Project)
- WebModel (JPA Project)
- WebView(Dynamic Web Project)
Problem is where to put persistance.xml file?
Getting exception:
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName DataModel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
persistence.xml 文件通常位于持久性 (JPA) 项目的 src/META-INF 目录中。如果项目是使用 Eclipse 创建的,则通常会默认创建并放置在那里。
The persistence.xml file is typically present in the
src/META-INF
directory of the persistence (JPA) project. If the project was created with Eclipse, it is typically created and placed there by default.JPA 2.0 规范第 8.2 节规定了打包要求。它说
如果您认为有必要,可以阅读本章的其余部分。在 Eclipse 中,这意味着您需要配置项目之间的依赖关系,以确保部署文件被正确打包。您通常在“项目”选项卡的“项目”->“属性”->“构建路径”中进行配置。
但是,我不确定 Eclipse 是否按照 Web 服务器部署的要求将其打包。我知道在 EAR 项目中确实如此。
The JPA 2.0 specification in section 8.2 states the requirements for packaging. It says
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.
However, I am not sure if Eclipse packages it up as required for Web server deployment. I know it does in a EAR project.
对于JPA项目甚至普通Java项目,您只需要在src下创建META-INF文件夹并在其中添加persistence.xml即可。就这样。现在,在 jvm 中加载应用程序时,它将自动获取。
项目结构
For JPA project or even for normal Java project, you just need to create META-INF folder under the src and add the persistence.xml there. That's all. now at the time of application loading in the jvm it will automatically be fetched.
project structure