JCvanDamme
JCvanDamme

Reputation: 671

JPA with Java SE: javax.persistence.PersistenceException: No Persistence provider for EntityManager

Executing a Java SE JPA standalone application throws the exception:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named test

I have found several similar posts but I think that none of them applies to my case with EclipseLink, Java SE and no packaging into deployable files and hence no WEB-INF etc.

The /src/META-INF/persistence.xml is:

<persistence>
    <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>SomeEntity</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/somedbname"/>
            <property name="javax.persistence.jdbc.user" value="foo"/>
            <property name="javax.persistence.jdbc.password" value="bar"/>
        </properties>
    </persistence-unit>
</persistence>

The following jars are on the build path:

Upvotes: 0

Views: 656

Answers (2)

JCvanDamme
JCvanDamme

Reputation: 671

I had to provide the persistence namespace in persistence.xml with the xmlns attribute

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

Upvotes: 1

Khalil M
Khalil M

Reputation: 1858

You have to add the eclipselink jar to your ClassPath to check is it's already there or no:

System.out.println(System.getProperty("java.class.path"));

Upvotes: 0

Related Questions