-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Getting NPE with Hibernate 5.1, WebLogic, and Spring
PostPosted: Wed Jul 13, 2016 9:30 pm 
Newbie

Joined: Wed Jul 13, 2016 9:26 pm
Posts: 3
Env : Weblogic 12c Clustered
Spring 4.2.5
Hibernate 5.1.0.Final

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.


Top
 Profile  
 
 Post subject: Re: Getting NPE when Hibernate 5.1 trying to locate Jndi Service
PostPosted: Thu Jul 14, 2016 1:36 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
These settings are no longer needed:

Code:
<entry key="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory" />
<entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />


since you have:

Code:
<entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform" />


You might want to remove this property too since it's not probably going to buy you anything:

Code:
<entry key="hibernate.bytecode.use_reflection_optimizer" value="true" />


If you use Spring, you don't need this setting too:

Code:
<entry key="hibernate.current_session_context_class" value="org.hibernate.context.JTASessionContext" />


I see that you already set the DataSource is Spring:

Code:
<property name="dataSource" ref="dataSourceXA" />


Make sure that the JNDI Context is available and you have access to the Weblogic TransactionManager which is located via JNDI.

Maybe the default naming used by Weblogic TransactionManager don't work for you and you need to supply the "userTransaction"/"userTransactionName" and "transactionManager"/"transactionManagerName" as well. Check the Weblogic TransactionManager documentation for that.


Top
 Profile  
 
 Post subject: Re: Getting NPE with Hibernate 5.1, WebLogic, and Spring
PostPosted: Thu Jul 14, 2016 1:50 am 
Newbie

Joined: Wed Jul 13, 2016 9:26 pm
Posts: 3
Thanks for your response. I am not sure if I mentioned before NPE in JndiService intermittently happening i.e. subsequent txns retries are succeeding. Can you plz throw some light about possible cause?

BTW : We recently upgraded from hibernate 3.6.10.Final [everything was working before]

While I was waiting for a response for my issue tried some changes to jpa properties but still getting intermittently NPE on jndiService and subsequent txn retries are working. WLS retries are configured 30 sec apart and number of retries are configured 4.

Below is the 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.transaction.JTATransactionFactory" />
<entry key="hibernate.jta.cacheTransactionManager" value="true" />
<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.hibernate.listeners.SessionFactoryMonitor" />
</map>
</property>
</bean>

<!-- StatisticsService is deprecated and is no longer supported, see HHH-6190 -->
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>

<bean id="hibernateStatisticsFactoryBean" class="xx.xx.xx.xx.HibernateStatisticsFactoryBean">
<property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
</bean>

<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING" />
<property name="beans">
<map>
<entry key="hibernate:type=hibernateStatistics" value-ref="hibernateStatisticsFactoryBean" />
</map>
</property>
</bean>

<bean id="dataSourceXA" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="resourceRef">
<value>false</value>
</property>
<property name="jndiName">
<value>#{systemProperties['DSName']}</value>
</property>
</bean>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="resourceRef">
<value>false</value>
</property>
<property name="jndiName">
<value>OracleDataSource</value>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"
autowire="default">
<property name="transactionManagerName" value="javax.transaction.TransactionManager" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
</beans>


Top
 Profile  
 
 Post subject: Re: Getting NPE with Hibernate 5.1, WebLogic, and Spring
PostPosted: Thu Jul 14, 2016 8:43 am 
Newbie

Joined: Wed Jul 13, 2016 9:26 pm
Posts: 3
Any inputs?


Top
 Profile  
 
 Post subject: Re: Getting NPE with Hibernate 5.1, WebLogic, and Spring
PostPosted: Thu Jul 14, 2016 10:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It's hard to tell just by looking on configs. A good old debug should do the trick.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.