Websphere找不到我的Hibernate管理的EntityManager

时间:2012-02-10 10:57:58

标签: hibernate spring openjpa websphere-7

我在Websphere 7上使用Hibernate 3.4,使用Spring 2.5.6

启动时,我的应用程序似乎遇到了Hibernate与OpenJPA的问题:

10/02/12 10:41:50:448 GMT] 00000010 LocalEntityMa I org.springframework.orm.jpa.LocalEntityManagerFactoryBean createNativeEntityManagerFactory Building JPA EntityManagerFactory for persistence unit 'mypu'
[10/02/12 10:41:50:495 GMT] 00000010 SystemErr     R   WARNING: Found unrecognized persistence provider "org.hibernate.ejb.HibernatePersistence" in place of OpenJPA provider.  This provider's properties will not be used.

...然后是一个可爱的堆栈跟踪:

  

PersistenceProvider [org.apache.openjpa.persistence.PersistenceProviderImpl@6b676b67]没有为名称'mypu'返回EntityManagerFactory

有关信息,我的持久性单元定义如下:

<?xml version="1.0" encoding="UTF-8"?>

<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_1_0.xsd"
    version="1.0">
    <persistence-unit name="mypu" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/serviceTrackerDS</jta-data-source>
        <class>...my classes...</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <!-- Properties for Hibernate & Derby -->
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
            <property name="hibernate.default_schema" value="APP"/>
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.use_sql_comments" value="true" />
        </properties>
    </persistence-unit>
</persistence>

我不知道该怎么办。似乎错误的持久性提供程序正在某处使用,但我在persistence.xml中指定了正确的提供程序。我知道OpenJPA是Websphere 7中的默认持久性管理器,但我想在这里使用Hibernate。

有什么建议吗?

1 个答案:

答案 0 :(得分:3)

我似乎需要在jpaVendorAdapter添加entityManagerFactory

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="mypu" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
</bean>

仍在测试,但作为一个解决方案看起来不错。