hibernate项目中persistence.xml的优先级

发布于 2024-10-01 23:43:44 字数 1100 浏览 2 评论 0原文

我有一个 Eclipse 项目,其中有几个 JPA/Hibernate 的 jar。其中一个包含 META-INF/persistence.xml,我想通过定义我自己的 persistence.xml 来覆盖它。因此,我尝试在 src/persistence.xmlsrc/META-INF/persistence.xml 中使用我的 persistence.xml 但每次看起来< code>jar/META-INF/persistence.xml 被拾取。 我还尝试编辑 Eclipse 项目的 .classpath 文件,并将 classpathentry path="bin" 向上移动到高于包含库,但仍然没有获取我的 persistence.xml

<classpath>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/rules"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>
    <classpathentry kind="con" path="DROOLS/Drools"/>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/drools"/>
</classpath>

在教程中我读到:

您需要覆盖这些 如果您想更改默认值, 通过添加您自己的 persistence.xml 您的类路径,位于默认值之前 drools-persistence-jpa.jar 中的一个

I have an eclipse project with several jars for JPA / Hibernate. One of tham contains a META-INF/persistence.xml and I want to override that by defining my own persistence.xml. So I tried using my persistence.xml in src/persistence.xml also src/META-INF/persistence.xml but everytime it seems jar/META-INF/persistence.xml gets picked up.
I also tried editing .classpath file of eclipse projects and moved up classpathentry path="bin" higher up than the library included but still its not picking up my persistence.xml

<classpath>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/rules"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>
    <classpathentry kind="con" path="DROOLS/Drools"/>
    <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/drools"/>
</classpath>

In the tutorial I read:

You will need to override these
defaults if you want to change them,
by adding your own persistence.xml in
your classpath, preceding the default
one in drools-persistence-jpa.jar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

安稳善良 2024-10-08 23:43:44

所以我尝试在 src/persistence.xml 和 src/META-INF/persistence.xml 中使用我的 persistence.xml 但每次似乎 jar/META-INF/persistence.xml 都会被选中。

persistence.xml 应位于 META-INF/persistence.xml 下,因此第一次尝试将不起作用。当我查看您的 .classpath 文件时,我没有看到 src 作为源路径,因此第二次尝试也不起作用。

尝试使用 src/main/java/META-INF/persistence.xml 来代替。

实际上,您的项目布局确实看起来像 Maven 布局,并且使用 Maven,资源通常会转到 src/main/resourcessrc/test/resources。但由于您没有提到您正在遵循什么教程,因此我无法确认这是否适用于此处。

无论如何,我的建议应该有效。

So I tried using my persistence.xml in src/persistence.xml also src/META-INF/persistence.xml but every time it seems jar/META-INF/persistence.xml gets picked up.

The persistence.xml should be located under META-INF/persistence.xml so the first attempt won't work. And when I look at your .classpath file, I don't see src as source path so the second attempt won't work either.

Try src/main/java/META-INF/persistence.xml instead.

Actually, your project layout really looks like a Maven layout and with Maven, resources typically go to src/main/resources or src/test/resources. But since you didn't mention what tutorial you're following, I can't confirm if this applies here.

Anyway, my suggestion should work.

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