我刚刚从Tomcat迁移到JBoss AS 7。 因此,我在JBoss中配置了Mysql数据源(添加了带有关联Jar的module.xml,将驱动程序块添加到standalone.xml并通过JBoss接口配置数据源。
部署时没有错误但是无法获得entityManager(后台使用Hibernate的JPA)。
确实,当执行此代码时:
Persistence.createEntityManagerFactory("RoomManagement");
我收到此错误:
javax.persistence.PersistenceException:没有持久性提供程序 EntityManager名为RoomManagement javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
非常奇怪,因为我已经证实我的persistence.xml确实发生在WEB-INF / classes / META-INF目录下的War中。
我的persistence.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="RoomManagement" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
<class>com.parisdescartes.roommanagement.domain.entities.Address</class>
<class>com.parisdescartes.roommanagement.domain.entities.Building</class>
<class>com.parisdescartes.roommanagement.domain.entities.Civility</class>
<class>com.parisdescartes.roommanagement.domain.entities.EventType</class>
<class>com.parisdescartes.roommanagement.domain.entities.Job</class>
<class>com.parisdescartes.roommanagement.domain.entities.Reservation</class>
<class>com.parisdescartes.roommanagement.domain.entities.Room</class>
<class>com.parisdescartes.roommanagement.domain.entities.RoomType</class>
<class>com.parisdescartes.roommanagement.domain.entities.Tool</class>
<class>com.parisdescartes.roommanagement.domain.entities.User</class>
<class>com.parisdescartes.roommanagement.domain.entities.UserDetail</class>
<class>com.parisdescartes.roommanagement.domain.entities.Schedule</class>
<properties>
<property name="hibernate.connection.autocommit" value="true" />
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
我犯了错误或忘记指定某事吗?
答案 0 :(得分:5)
从WEB-INF/lib
中删除休眠jar。 JBoss有捆绑,所以如果你在类路径上有它,它可能会混淆类加载器。