javax.persistence.PersistenceException:没有名为 XX 的 EntityManager 的持久性提供程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18233975/
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
javax.persistence.PersistenceException: No Persistence provider for EntityManager named XX
提问by Jasper
I have a simple JPA/Hibernate Project in Eclipse (Helios) IDE. I have placed the persistence.xml in Project>resources dir. And in Eclipse i have added this directory(Project\resources) to the classpath.
我在 Eclipse (Helios) IDE 中有一个简单的 JPA/Hibernate 项目。我已将 persistence.xml 放在 Project>resources 目录中。在 Eclipse 中,我已将此目录(Project\resources)添加到类路径中。
Yet when i run my appln frm within Eclipse IDE, i see this error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named XX
然而,当我在 Eclipse IDE 中运行我的 appln frm 时,我看到了这个错误: javax.persistence.PersistenceException: No Persistence provider for EntityManager named XX
In Eclipse, i've following Libraries: hibernate3.jar hibernate-jpa-2.0-api-1.0.0.Final.jar hibernate-entitymanager-3.6.0.Final.jar and rest are supporting jars...
在 Eclipse 中,我有以下库: hibernate3.jar hibernate-jpa-2.0-api-1.0.0.Final.jar hibernate-entitymanager-3.6.0.Final.jar 和其余的支持罐子...
My persistence.xml is:
我的persistence.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="XX" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- the JNDI data source -->
<non-jta-data-source>java:comp/env/jdbc/tutorialDS</non-jta-data-source>
<properties>
...
</properties>
</persistence-unit>
</persistence>
What is causing this error in Eclipse IDE? Thanks
是什么导致 Eclipse IDE 出现此错误?谢谢
采纳答案by Jasper
So the solution:
所以解决方案:
In Eclipse > Properties > Java Build Path
Source Tab - there was: Excluded: META-INF/
This was causing the META-INF dir to be completely ignored, and persistence.xml was not found.
On deleting that Excluded:META-INF/ line, persistence.xml is now found successfully.
在 Eclipse > Properties > Java Build Path
Source Tab 中 - 有: Excluded: META-INF/
这导致 META-INF 目录被完全忽略,并且没有找到 persistence.xml。
删除该 Excluded:META-INF/ 行后,现在可以成功找到 persistence.xml。
How did- Excluded: META-INF/ end up in Java Build Path > 'Source' tab?
Earlier under the 'Libraries' Tab, i had done: 'Add Class Folder' : src/META-INF
This automatically resulted in Excluded: META-INF/ under 'Source' tab.
如何 - 排除:META-INF/ 最终出现在 Java 构建路径 >“源”选项卡中?
早些时候在“库”选项卡下,我做了:“添加类文件夹”:src/META-INF
这会自动导致“源”选项卡下的排除:META-INF/。
Hope this helps someone.
希望这可以帮助某人。
回答by Shamim Ahmmed
Have you tried to keep this persistence.xml file into class path META-INF
folder.
您是否尝试将此persistence.xml 文件保存到类路径META-INF
文件夹中。
{CLASS_PATH}/META-INF/persistence.xml
回答by Guillermo
The persistence.xml must be placed inside META-INF directory.
persistence.xml 必须放在 META-INF 目录中。
Edit: don't forget include the library of the driver for your database.
编辑:不要忘记为您的数据库包含驱动程序库。