问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/9226692/websphere-cant-find-my-hibernate-managed-entitymanager