我尝试将项目从GlassFish迁移到Weblogic 12c。
我使用Hibernate 4.2.17并且出现以下错误 当我的代码被调用以在Container中创建EntityManager时。
Caused By: java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory.isJoinableJtaTransaction(CMTTransactionFactory.java:63)
at org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory.isJoinableJtaTransaction(CMTTransactionFactory.java:39)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.isTransactionJoinable(TransactionCoordinatorImpl.java:311)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1215)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:178)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:89)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:193)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:188)
at weblogic.persistence.PersistenceContextWrapper.<init>(PersistenceContextWrapper.java:26)
at weblogic.persistence.TransactionalEntityManagerProxyImpl.newPersistenceContext(TransactionalEntityManagerProxyImpl.java:152)
at weblogic.persistence.TransactionalEntityManagerProxyImpl.getPersistenceContext(TransactionalEntityManagerProxyImpl.java:128)
at weblogic.persistence.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:94)
at weblogic.persistence.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:164)
at weblogic.persistence.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:86)
at com.sun.proxy.$Proxy346.createNamedQuery(Unknown Source)
at rpm.jpa.crudservice.RpmJPAServiceImpl.findByNamedQuerySingle(RpmJPAServiceImpl.java:302)
persistence.xml:
<persistence-unit name="My_JPA_UNIT" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>MyDS</jta-data-source>
<class>....</class>
<class>....</class>
<properties>
<property name="hibernate.generate_statistics" value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.level" value="ALL" />
<property name="hibernate.logging.level" value="ALL" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" />
<property name="hibernate.transaction.jta.platform" value="org.hibernate.engine.transaction.jta.platform.internal.WebLogicJtaPlatform" />
</properties>
</persistence-unit>
我的代码:
@Stateless
@Local(RpmJPAService.class)
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class RpmJPAServiceImpl implements RpmJPAService
{
@PersistenceContext(unitName = "My_JPA_UNIT")
EntityManager em;
@SuppressWarnings("unchecked")
@Override
public <T>T findByNamedQuerySingle(final String queryName, final Object... parameters) throws PsAccessException
{
logQueryNameAndParameters(queryName, parameters);
try
{
(line 302) final Query q = setQueryParameters(em.createNamedQuery(queryName), parameters);
return (T) q.getSingleResult();
}
catch(final NoResultException nre)
{
return null;
}
catch(final PersistenceException pe)
{
throw handleQuerySingleException(pe);
}
}
}
是否有人遇到此错误?
答案 0 :(得分:2)
通过在Hibernate 4.2.17中调试,我发现无法正确加载WeblogicJtaPlatform,这与Weblogic中Hibernate 4.2.17的ClassLoader有关。 (还有hibernate.transaction.jta.platform实现类的包名称不同)
我将我的应用程序升级到Hibernate 4.3.10,并在persistence.xml中进行了一些更改,例如
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<property name="hibernate.transaction.jta.platform" value="Weblogic" />
现在解决了WebLogicJtaPlatform的问题。