未找到PersistenceProvider org.hibernate.ejb.HibernatePersistence

时间:2014-02-18 07:52:26

标签: hibernate ejb jboss7.x

在将EJB EAR部署到JBoss7.1服务器时,我收到以下异常:

Caused by: javax.persistence.PersistenceException: JBAS011466: PersistenceProvider '
            org.hibernate.ejb.HibernatePersistence
        ' not found

我在EJB中添加了以下jar(这些jar也位于我的jboss模块jboss_home/modules/org/hibernate/main中):

hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.0.1.Final.jar
hibernate-entitymanager-4.0.1.Final.jar
hibernate-infinispan-4.0.1.Final.jar

以下是我在persistence.xml文件中添加hibernate提供程序的方法:

<persistence 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"
    version="2.0">
    <persistence-unit name="hbPU" transaction-type="RESOURCE_LOCAL">
        <provider>
            org.hibernate.ejb.HibernatePersistence
        </provider>
        ...
    </persistence-unit>
</persistence>

2 个答案:

答案 0 :(得分:2)

我试过了...... 创建一个java类HibernateUtil.java并将持久性单元名称提供给entityManagerFactory = Persistence.createEntityManagerFactory(“abc”);

public class HibernateUtil {

    private static final EntityManagerFactory entityManagerFactory;
    static {
                try {
                     entityManagerFactory = Persistence.createEntityManagerFactory("hbPU");  // here is your persistence unit name
                     System.out.println("Entity Menager Test.............."+ entityManagerFactory);
                } catch (Throwable ex) {

                    System.err.println("Initial SessionFactory creation failed." + ex);
                    throw new ExceptionInInitializerError(ex);

                  }
    }

public static EntityManagerFactory getEntityManagerFactory() {
         return entityManagerFactory;
    }

}

并像这样创建你的persistence.xml

<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="hbPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!-- map your classes. -->
    <properties>
    <property name="javax.persistence.jdbc.driver" value="xxx" />
    <property name="javax.persistence.jdbc.url"value="xxx"/>
    <property name="javax.persistence.jdbc.user" value="xxx" />
    <property name="javax.persistence.jdbc.password" value="xxx" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    <property name="hibernate.hbm2ddl.auto" value="create-drop" />
    <property name="hibernate.show_sql" value="true" />
    </properties>
        </persistence-unit>
    </persistence>

你的错误不会来......

答案 1 :(得分:-1)

我有同样的错误。我所要做的只是将提供者参数放入1行

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

<provider>
  org.hibernate.jpa.HibernatePersistenceProvider
</provider>