【问题标题】:Websphere can't find my Hibernate-managed EntityManagerWebsphere 找不到我的 Hibernate 管理的 EntityManager
【发布时间】:2012-03-02 20:35:37
【问题描述】:

我在 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 为持久性单元“mypu”构建 JPA EntityManagerFactory [10/02/12 10:41:50:495 GMT] 00000010 SystemErr R 警告:发现无法识别的持久性提供程序“org.hibernate.ejb.HibernatePersistence”代替 OpenJPA 提供程序。不会使用此提供程序的属性。

...然后是由以下原因引起的可爱的堆栈跟踪:

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。

有什么建议吗?

【问题讨论】:

    标签: hibernate spring openjpa websphere-7


    【解决方案1】:

    看来我需要将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>
    

    仍在测试,但看起来不错。

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 2016-12-23
      • 2021-09-13
      相关资源
      最近更新 更多