Websphere无法找到我的Hibernate管理的EntityManager [英] Websphere can't find my Hibernate-managed EntityManager

查看:107
本文介绍了Websphere无法找到我的Hibernate管理的EntityManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Websphere 7上使用Hibernate 3.4,使用Spring 2.5.6在开始时,我的应用程序在Hibernate和OpenJPA之间似乎有问题:

p>

 
10/02/12 10:41:50:448 GMT] 00000010 LocalEntityMa I org.springframework.orm.jpa.LocalEntityManagerFactoryBean createNativeEntityManagerFactory构建JPA EntityManagerFactory [10/02/12 10:41:50:495 GMT] 00000010 SystemErr R WARNING:发现无法识别的持久性提供程序org.hibernate.ejb.HibernatePersistence取代OpenJPA提供程序。这个提供者的属性将不会被使用。

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


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


对于信息,我的持久性单元定义如下:

 <?xml version =1.0encoding = 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 =myputransaction-type =JTA>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
< jta-data-source> jdbc / serviceTrackerDS< / jta-data-source>
< class> ...我的课程...< / class>
< exclude-unlisted-classes> true< / exclude-unlisted-classes>
<! - Hibernate的属性&德比 - >
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.DerbyDialect/>
< property name =hibernate.default_schemavalue =APP/>
< property name =hibernate.hbm2ddl.autovalue =create/>
< property name =hibernate.show_sqlvalue =true/>
< property name =hibernate.use_sql_commentsvalue =true/>
< / properties>
< / persistence-unit>
< /余辉>

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



任何建议?

解决方案

看来我需要向我的 entityManagerFactory jpaVendorAdapter c $ c $。

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

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

I'm using Hibernate 3.4 on Websphere 7, with Spring 2.5.6

On startup, my application seems to have problems with Hibernate vs. 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>

I'm not sure how to proceed. It seems like the wrong persistence provider is being used somewhere, but I have specified the correct provider in persistence.xml. I know that OpenJPA is the default persistence manager in Websphere 7, but I'd like to use Hibernate here.

Any advice?

解决方案

It appears that I needed to add a jpaVendorAdapter to my 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>

Still testing but looks good as a resolution.

这篇关于Websphere无法找到我的Hibernate管理的EntityManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆