开发者

Java persistence entity manager factory returning null

I am using MySql database with JPA. my persistence.xml looks like

<?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>

in my java code i do the followi开发者_开发知识库ng

EntityManagerFactory emf = Persistence.createEntityManagerFactory("citheph");
EntityManager em = emf.createEntityManager();

emf always come back null. the database is connected and pings successfully. I have even tried to change the persistence-unit name to something that doesn't match the entry in the persistance.xml and I am still getting null. It is not throwing any exceptions. ofcourse when it gets to the second line in the code

EntityManager em = emf.createEntityManager();

I get a null pointer exception.

any help will be greatly appreciated.


Turn logging on finest and ensure no errors are occurring loading the persistence unit.

What environment are you using, do you have all the required jars on your classpath?


Are you sure that the persistence.xml files resides in the META-INF folder?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜