在Hibernate 5.1尝试定位Jndi服务时获取NPE

时间:2016-07-13 13:50:33

标签: hibernate spring-orm

症状:在处理下面粘贴NPE堆栈跟踪的消息时间歇性地处理MDB,但在后续重试时错误似乎消失了:

Env : Weblogic 12c  Clustered 
      Spring 4.2.5
      Hibernate 5.1.0.Final  

Hibernate stacktrace: -

  java.lang.NullPointerException
            at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.jndiService(AbstractJtaPlatform.java:46)
            at org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform.locateTransactionManager(WeblogicJtaPlatform.java:24)
            at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.retrieveTransactionManager(AbstractJtaPlatform.java:92)
            at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.getTransactionManager(AbstractJtaPlatform.java:98)
            at org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy.canRegisterSynchronization(TransactionManagerBasedSynchronizationStrategy.java:39)
            at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.canRegisterSynchronization(AbstractJtaPlatform.java:131)
            at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.pulse(JtaTransactionCoordinatorImpl.java:141)
            at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.<init>(JtaTransactionCoordinatorImpl.java:92)
            at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl.buildTransactionCoordinator(JtaTransactionCoordinatorBuilderImpl.java:28)
            at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:277)
            at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1322)
            at org.hibernate.jpa.internal.EntityManagerImpl.internalGetSession(EntityManagerImpl.java:133)
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:174)
            at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:83)
            at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:319)
            at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:286)
            at sun.reflect.GeneratedMethodAccessor726.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:407)
            at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:560)
            at com.sun.proxy.$Proxy892.createEntityManager(Unknown Source)
            at org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetTransactionalEntityManager(EntityManagerFactoryUtils.java:285)
            at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:255)
            at com.sun.proxy.$Proxy895.createQuery(Unknown Source)
            at 

JPA specific config :-

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="packagesToScan">
            <list>
                <value>xx.xx</value>
                <value>xx.xx</value>
            </list>
        </property>

        <property name="dataSource" ref="dataSourceXA" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false" />
                <property name="generateDdl" value="false" />
                <property name="database" value="ORACLE" />
                <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
            </bean>
        </property>

        <!-- configure Hibernate -->
        <property name="jpaPropertyMap">
            <map>
                <entry key="javax.persistence.transactionType" value="jta" />
                <entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform" />
                <entry key="hibernate.event.merge.entity_copy_observer" value="allow" />

                <entry key="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory" />
                <entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
                <entry key="hibernate.current_session_context_class" value="org.hibernate.context.JTASessionContext" />
                <entry key="hibernate.bytecode.use_reflection_optimizer" value="true" />

                <entry key="hibernate.order_updates" value="true" />
                <entry key="hibernate.generate_statistics" value="true" />
                <entry key="hibernate.ejb.session_factory_observer" value="xx.xx.xx.xx.xx.hibernate.listeners.SessionFactoryMonitor" />
            </map>
        </property>
    </bean>

Hibernate 5.1 source code where error is coming :-

protected JndiService More ...jndiService() {
    return serviceRegistry().getService( JndiService.class );
}

Either serviceRegistry() returning null or call to getService encountering NPE and it is rethrowing , any help appreciated. 

0 个答案:

没有答案