部署我的应用程序后出现了这样的异常:
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)
,在这一行失败了:
private EntityManager em = Persistence.createEntityManagerFactory("JavaAcademyUnit").createEntityManager();
JPA配置描述符 persistance.xml 文件位于正确的位置: ./ WEB-INF / classes / META-INF / persistence.xml < / strong>并包含:
<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 包含:
<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>
感谢您的帮助!
答案 0 :(得分:0)
最后,经过4小时的谷歌搜索,我找到了原因:
Artifacts文件夹的根目录中必须包含 lib 文件夹,并带有所需的库:
希望它会对某人有所帮助。