eclipse Persistence.createEntityManagerFactory() 在哪里寻找持久化单元?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26367983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
where does Persistence.createEntityManagerFactory() look for the persistence unit?
提问by CodeMed
I am using eclipse. I am trying to debug a failure to find the persistence unit that is indeed located in the directory structure of my eclipse project.
我正在使用日食。我正在尝试调试无法找到确实位于我的 eclipse 项目目录结构中的持久性单元。
Where does EntityManagerFactory javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties)
look for the persistence unit?
在哪里EntityManagerFactory javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties)
寻找持久性单元?
When I ask where it looks, I mean all the possible resources that could get searched, including eclipse configurations, properties in persistence.xml if the file is found, resources searched by included JARs, etc. To explore how this works, I am executing a test program by right clicking on a Main.java class located in the root (src/main/java
) of an eclipse project.
当我问它看起来在哪里时,我的意思是可以搜索到的所有可能的资源,包括 eclipse 配置、persistence.xml 中的属性(如果找到文件)、包含的 JAR 搜索的资源等。为了探索它是如何工作的,我正在执行通过右键单击位于src/main/java
eclipse 项目根 ( ) 中的Main.java 类来创建测试程序。
The answer might help me figure out how to configure the eclipse project so that EntityManagerFactory javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties)
can find the persistence unit.
答案可能会帮助我弄清楚如何配置 eclipse 项目以便EntityManagerFactory javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties)
可以找到持久性单元。
采纳答案by mendieta
It searches your persistence.xml, located inside your META-INF dir. This folder has to be at the same level as your root package.
它会搜索位于 META-INF 目录中的 persistence.xml。此文件夹必须与您的根包处于同一级别。
In a maven project, the folder would be in /src/main/resources/META-INF/persistence.xml
在 maven 项目中,该文件夹位于 /src/main/resources/META-INF/persistence.xml