EclipseLink JPA - persistence.xml 的位置
我正在将 JPA 用于 java 类,但无法将持久性 XML 文件放在它应该在的位置。
我使用的 IDE 是 Eclipse Helios。 Eclipselink jar 文件已下载并添加到我的 JRE 系统库等中。在收到以下错误后,我用标签编写了 persistence.xml :
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named customers
Provider tag:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
The program still does not run 所以我想知道应该将 persistence.xml 放在哪里(即 src/main/resources 或 lib/META- INF...等)
I am using JPA for a java class and having trouble putting the persistence XML file where it should be.
The IDE i am using is Eclipse Helios. Eclipselink jar files are downloaded and added to my JRE System Library and all. I wrote up the persistence.xml with the tag after getting the following error :
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named customers
Provider tag:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
The program still doesn't run so i am wondering where should I place persistence.xml (i.e src/main/resources, or lib/META-INF... etc )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
persistence.xml
应该放在 classpath 根目录下名为META-INF
的目录中。在 Eclipse 中右键单击您的项目==>属性==> Java 构建路径。假设您将构建路径之一配置为
/src/main/resources
,那么您应该将persistence.xml
放在/src/main/resources/ META-INF/persistence.xml
persistence.xml
should be put inside an directory calledMETA-INF
under the root of the classpath .Right click your project in eclipse ==> Properties ==> Java Build Path . Suppose you configure one of the build paths to be
/src/main/resources
, then you should put thepersistence.xml
at/src/main/resources/META-INF/persistence.xml
JPA 持久性 XML 文件位置
传统上,persistence.xml 位于需要驻留在 Java 类路径根目录中的
META-INF
文件夹中。如果您使用 Maven,则可以将其存储在resources
文件夹中,如下所示:JPA persistence XML file location
Traditionally, the persistence.xml is located in a
META-INF
folder that needs to reside in the root of the Java classpath. If you’re using Maven, you can store it in theresources
folder, like this: