我正在使用MySql数据库和JPA。我的persistence.xml看起来像Java持久性实体管理器工厂返回null
<?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>
在我的Java代码
我这样做
EntityManagerFactory emf = Persistence.createEntityManagerFactory("citheph");
EntityManager em = emf.createEntityManager();
电动势总会回来空。数据库已连接并且ping成功。我甚至试图将持久性单元名称更改为与persistance.xml中的条目不匹配,并且仍然为空。它没有抛出任何例外。当它到达代码中的第二行时
EntityManager em = emf.createEntityManager();
我得到一个空指针异常。
任何帮助将不胜感激。
谢谢。我使用的是一个不同的库,而不是eclips。感谢您的时间 – Amer
你如何打开最好的日志? –