Java持久性实体管理器工厂返回null
我正在使用带有JPA的MySql数据库。我的persistence.xml看起来像Java持久性实体管理器工厂返回null,java,mysql,eclipse,jpa,persistence,Java,Mysql,Eclipse,Jpa,Persistence,我正在使用带有JPA的MySql数据库。我的persistence.xml看起来像 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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_2_0.xsd">
<persistence-unit name="citheph">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>persistence.citheph.pTerm</class>
<class>persistence.citheph.pPublicationterm</class>
<class>persistence.citheph.pPublicationauthor</class>
<class>persistence.citheph.pPublication</class>
<class>persistence.citheph.pCoauthorship</class>
<class>persistence.citheph.pCitation</class>
<class>persistence.citheph.pAuthor</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/cithepth" />
<property name="javax.persistence.jdbc.password" value="amer1" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
</properties>
</persistence-unit>
</persistence>
emf总是返回空值。数据库已连接并成功ping。我甚至尝试将持久性单元名称更改为与persistence.xml中的条目不匹配的名称,但仍然得到null。它没有抛出任何异常。当然,当它到达代码中的第二行时
EntityManager em = emf.createEntityManager();
我得到一个空指针异常
任何帮助都将不胜感激 您确定persistence.xml文件位于META-INF文件夹中吗?打开日志记录,确保加载持久化单元时没有发生错误
您使用的是什么环境,类路径上是否有所有必需的jar?谢谢。我使用的是一个不同于eclips库的持久性类库。感谢您的时间,您如何打开登录?
EntityManager em = emf.createEntityManager();