hibernate - Websphere 找不到我的 Hibernate 管理的 EntityManager

标签 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.

... and then a lovely stack trace caused by:

PersistenceProvider [org.apache.openjpa.persistence.PersistenceProviderImpl@6b676b67] did not return an EntityManagerFactory for name 'mypu'

For info, my persistence unit is defined as follows:

<?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。

有什么建议吗?

最佳答案

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

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

关于hibernate - Websphere 找不到我的 Hibernate 管理的 EntityManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9226692/

相关文章:

java - 如何创建从内存到数据库的后写缓存?

jpa-2.0 - 无法从 HSQLDB 生成 JPA 实体

java - @OneToOne 未使用 OpenJPA 在 CriteriaBuilder 中获取

linq - ORM(Linq、Hibernate...)真的那么有用吗?

java - org.hibernate.dialect.PostgresPlusDialect 与 org.hibernate.dialect.PostgreSQL9Dialect 之间有什么区别?

java - hibernate : ORA-00907: missing right parenthesis

java - 使 Spring 3 MVC Controller 方法成为事务性的

java - 在 @Transactional 方法之前创建的 Hibernate 对象不能在之后使用(获取 LazyInitializationException)

java - 如何构建与 Spring Elasticsearch 存储库中的短语之一匹配的查询