EclipseLink JPA - persistence.xml 的位置

发布于 2024-12-18 00:45:14 字数 552 浏览 3 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆头 2024-12-25 00:45:14

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 called META-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 the persistence.xml at /src/main/resources/META-INF/persistence.xml

梦在深巷 2024-12-25 00:45:14

JPA 持久性 XML 文件位置

传统上,persistence.xml 位于需要驻留在 Java 类路径根目录中的 META-INF 文件夹中。如果您使用 Maven,则可以将其存储在 resources 文件夹中,如下所示:

src/main/resources/META-INF/persistence.xml

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 the resources folder, like this:

src/main/resources/META-INF/persistence.xml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文