2
votes

I am having a No Persistence provider for EntityManager exception, and can't figure out what is causing it. Here is my configuration file:

Persistence.xml (stored in src/META-INF)

<?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="HatifimJPA" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>entities.HatUser</class>
        <properties>
            <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
            <property name="hibernate.connection.username" value="Benny" />
            <property name="hibernate.connection.password" value="oracle" />
            <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
        </properties>
    </persistence-unit>
</persistence>

Exception:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named HatifimJPA at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at testing.TestClass.main(TestClass.java:16)

The only difference is that I am trying to get the EntityManager into a public void main(...) { ... } block, however, I don't recall having a problem doing that in the past.

Can anyone help to point out where my problem might reside?

1
Post your exception trace to analyze.Ahamed Mustafa M
Is it a desktop app or a webapp?SJuan76
It's going to be a webapp, but for now it's just a JPA project with a main classBennyz
I do not see anything wrong but I am not expert; it looks like some configuration issue that prevents the PU from being created. I would try to connect to the DB directly to the ODBC, to check if configuration is ok. Also I would point to where the PU is created/retrieved.SJuan76
The listener service was actually down, but I still get the same exceptionBennyz

1 Answers

3
votes

Try putting the persistence.xml to src/main/resources/META-INF/ and put this code to the main method:

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