Question

I get such an exception after deploying my application:

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named JavaAcademyUnit
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at com.bogdankobylinsky.javaacademy.dao.impl.jpa.UserJPADAO.<init>(UserJPADAO.java:13)

, which fails on this line:

 private EntityManager em = Persistence.createEntityManagerFactory("JavaAcademyUnit").createEntityManager();

JPA configuration descriptor persistance.xml file is located in the right place: ./WEB-INF/classes/META-INF/persistence.xml and contains:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="JavaAcademyUnit" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/__JavaAcademy</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

pom.xml contains:

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>

Thanks for any help!

Was it helpful?

Solution

Finally, after 4 hours of googling, I found the reason:

Artifacts folder must have lib folder in its root with needed libraries:

lib folder

Hope it will help someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top