hibernate项目中persistence.xml的优先级
我有一个 Eclipse 项目,其中有几个 JPA/Hibernate 的 jar。其中一个包含 META-INF/persistence.xml
,我想通过定义我自己的 persistence.xml
来覆盖它。因此,我尝试在 src/persistence.xml
和 src/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
persistence.xml
应位于META-INF/persistence.xml
下,因此第一次尝试将不起作用。当我查看您的.classpath
文件时,我没有看到src
作为源路径,因此第二次尝试也不起作用。尝试使用 src/main/java/META-INF/persistence.xml 来代替。
实际上,您的项目布局确实看起来像 Maven 布局,并且使用 Maven,资源通常会转到
src/main/resources
或src/test/resources
。但由于您没有提到您正在遵循什么教程,因此我无法确认这是否适用于此处。无论如何,我的建议应该有效。
The
persistence.xml
should be located underMETA-INF/persistence.xml
so the first attempt won't work. And when I look at your.classpath
file, I don't seesrc
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
orsrc/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.