Search code examples
javahibernatejakarta-eejpa

No persistence provider for EntityManager, JPA configuration


I try to configure JPA Hibernate with the following persistence.xml :

<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <mapping-file>orm.xml</mapping-file>

    <properties>
        <property name="javax.persistence.jdbc.driver" value="x" />
        <property name="javax.persistence.jdbc.url"
            value="x;create=true" />
        <property name="javax.persistence.jdbc.user" value="x" />
        <property name="javax.persistence.jdbc.password" value="x" />
        <property name="dialect" value="org.hibernate.dialect.DB2Dialect" />
        <!-- EclipseLink should create the database schema automatically -->
        <!-- <property name="eclipselink.ddl-generation" value="create-tables" 
            /> <property name="eclipselink.ddl-generation.output-mode" value="database" 
            /> -->
    </properties>

</persistence-unit>

in the place "x" there are proper values, but I got:

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named manager1
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at de.volkswagen.webpromet.Main.main(Main.java:10)

Thanks for help ! ! !


Solution

  • It is the place clearly showed where should be placed persistence.xml

    TIP: Documentation is the best TUTORIAL !

    src
    |-- main
    |   |-- java
    |   `-- resources
    |       |-- jpa
    |       |   |-- Clerk-orm.xml
    |       |   |-- Customer-orm.xml
    |       |   |-- Person-orm.xml
    |       |   `-- Sale-orm.xml
    |       `-- META-INF
    |           `-- persistence.xml
    `-- test
        `-- resources
            `-- hibernate.properties
    

    More here: http://webdev.apl.jhu.edu/~jcs/ejava-javaee/coursedocs/605-784-site/docs/content/html/hibernate-migration-orm.html#hibernate-migration-orm-mapping