-->
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.  [ 8 posts ] 
Author Message
 Post subject: Hibernate Entity Manager JPA issue on WebSphere 6.1
PostPosted: Mon Feb 25, 2008 7:35 am 
Newbie

Joined: Mon Feb 25, 2008 6:20 am
Posts: 2
Hi,
I am facing issue while using Hibernate based JPA implementation (Hibernate entity manager) on WebSphere 6.1 application server. Hibernate version in use is 3.3
The application in question gets deployed as EAR file. Following are some key information:

JPA Usage: The application use case have JPA based DAO. The persistence.xml file has Hibernate as Provider.

Case 1:
- The JPA based DAO has bean managed transaction
- inside peristence.xml the transaction-type is set as RESOURCE_LOCAL
- Application behaves inconsistently and exception thrown is javax.persistence.PersistenceException: org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager


CASE 2:

- The JPA based DAO has bean managed transaction
- inside peristence.xml the transaction-type is set as JTA
- the values in the database are not getting updated and also no exception is thrown

The interseting thing the same application works fine on BEA Weblogic 9.2 and JBoss app server. After swicthing the JPA implementatin to Apache OpenJPA application works fine.

Please let me know the possible solution or some pointers for same.

Regards,
Anil


Top
 Profile  
 
 Post subject: Re: Hibernate Entity Manager JPA issue on WebSphere 6.1
PostPosted: Mon Feb 25, 2008 11:43 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Are you using spring?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 12:05 pm 
Newbie

Joined: Mon Feb 25, 2008 6:20 am
Posts: 2
Thanks for your reply.

Yes I am using Spring 2.0 version but it's not used directly.

please let me know if you know anything about this issue.

Regards,
Anil


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 12:07 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
There was an issue with Spring/Hibernate/Web Sphere combination that was fixed a few weeks ago. Update your spring jars and see if the problem goes away.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 8:26 pm 
Newbie

Joined: Sun Mar 09, 2008 8:19 pm
Posts: 2
farzad wrote:
There was an issue with Spring/Hibernate/Web Sphere combination that was fixed a few weeks ago. Update your spring jars and see if the problem goes away.


Farzad-


Farzad,

Like the OP, I too have just run into this issue. Like him, I'm also NOT using Spring. The IBM Tech docs state to use ONLY the following values in the transaction persistence with WAS6.1 and Hibernate:

<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
<property name="jta.UserTransaction" value="java:comp/UserTransaction" />

But, when you do this under WAS6.1 with Hibernate and EntityManager you just get the following exception the moment you try to get an EntityManager in a servlet:

[10/03/08 00:16:56:953 GMT] 0000001d ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: TestServlet. Exception thrown : org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:185)


I've tried every possible combination, but I've never got beyond this failure to sync with the TM.

Any ideas?

Cheers,

Nomadd


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 10:52 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What hibernate version are you using? and give me the whole stack trace. Are you starting a transaction manually or you are waiting for hibernate to start one?



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 22, 2008 5:47 am 
Newbie

Joined: Sun Mar 09, 2008 8:19 pm
Posts: 2
farzad wrote:
What hibernate version are you using? and give me the whole stack trace. Are you starting a transaction manually or you are waiting for hibernate to start one?



Farzad-


Hi Farzad,

Sorry I've taken so long to reply, I've been on holiday.

Hibernate is version 3.2.6. Annotations 3.3.0 GA. Entity Manager 3.3.1 GA.

The complete stack trace is given below, as is the persistence.xml settings I mentioned above. I don't actually get as far as any transactions, as I get the same error as the other posters (I've done a search of all the forums round here and people seem to be hitting the exact same issue) when trying to get an EntityManager. You can get an EntityManagerFactory OK (see the debug trace in the stack trace below) but the failure occurs when you try to get the EntityManager. I've just placed this code in the init() method of a test Servlet for now.

Here's the settings from the persistence.xml file:

<?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" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd">
<persistence-unit name="sptest" transaction-type="JTA">
<jta-data-source>jdbc/sptest</jta-data-source>
<class>event.Event</class>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
<property name="jta.UserTransaction"
value="java:comp/UserTransaction" />
</properties>
</persistence-unit>
</persistence>


Here's the complete (well, as much as WebSphere logs) stack trace:

[22/03/08 09:37:12:968 GMT] 00000021 SystemOut O Creating EntityManagerFactory...
[22/03/08 09:37:12:968 GMT] 00000021 SystemOut O Creating EntityManager...
[22/03/08 09:37:13:046 GMT] 00000021 ServletWrappe E SRVE0100E: Did not realize init() exception thrown by servlet Controller: org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:185)
at org.hibernate.impl.SessionImpl.checkTransactionSynchStatus(SessionImpl.java:1867)
at org.hibernate.impl.SessionImpl.isOpen(SessionImpl.java:320)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:448)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:37)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:37)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:32)
at util.JPAUtil.getEntityManager(JPAUtil.java:50)
at spweb.Controller.init(Controller.java:36)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:190)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:317)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:346)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: java.lang.UnsupportedOperationException
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getStatus(WebSphereExtendedJTATransactionLookup.java:87)
at org.hibernate.transaction.JTATransactionFactory.isTransactionInProgress(JTATransactionFactory.java:94)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:191)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:159)
... 31 more

[22/03/08 09:37:13:062 GMT] 00000021 ServletWrappe E Deregister the mbean because of uncaught init() exception thrown by servlet Controller: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception thrown by servlet
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:242)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:317)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:346)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
---- Begin backtrace for Nested Throwables
org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:185)
at org.hibernate.impl.SessionImpl.checkTransactionSynchStatus(SessionImpl.java:1867)
at org.hibernate.impl.SessionImpl.isOpen(SessionImpl.java:320)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:448)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:37)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:37)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:32)
at util.JPAUtil.getEntityManager(JPAUtil.java:50)
at spweb.Controller.init(Controller.java:36)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:190)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:317)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:346)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: java.lang.UnsupportedOperationException
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getStatus(WebSphereExtendedJTATransactionLookup.java:87)
at org.hibernate.transaction.JTATransactionFactory.isTransactionInProgress(JTATransactionFactory.java:94)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:191)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:159)
... 31 more
,
[22/03/08 09:37:13:078 GMT] 00000021 WebApp E [Servlet Error]-[Controller]: org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:185)
at org.hibernate.impl.SessionImpl.checkTransactionSynchStatus(SessionImpl.java:1867)
at org.hibernate.impl.SessionImpl.isOpen(SessionImpl.java:320)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:448)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:37)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:37)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:32)
at util.JPAUtil.getEntityManager(JPAUtil.java:50)
at spweb.Controller.init(Controller.java:36)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:190)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:317)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:346)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: java.lang.UnsupportedOperationException
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getStatus(WebSphereExtendedJTATransactionLookup.java:87)
at org.hibernate.transaction.JTATransactionFactory.isTransactionInProgress(JTATransactionFactory.java:94)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:191)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:159)
... 31 more


It's also worth noting that it's the following lines (i.e. those that allow Hibernate to bind to the JPA provider) that cause the issue:

<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
<property name="jta.UserTransaction"
value="java:comp/UserTransaction" />

If you actually remove them, and just have the following line:

<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />


And then manage the JTA transactions yourself with code like:

UserTransaction utx =null;
try {
utx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
utx.begin();
... DO SOME HIBERNATE STUFF HERE

Then it works fine. Clearly this is quite messy, though, as you really want Hibernate to just bind to any existing JTA transaction manager. I found the above tip in one of the postings in the EntityManager forum on here. Another thing that people say seems to work is if you ditch the EntityManager and it's Factory and just go back to using an hibernate.xml file and Session and Sessionfactory (i.e. Hibernate core.) That's what IBM seem to have tested, as the persistence.xml settings I show above are listed on their site under the hibernate.xml mapping notation, not persistence.xml notation. I haven't tried moving all of my stuff back to Session/SessionFactory, as that isn't the way I want to go; I'd rather stick with JPA compliant stuff in WebSphere 6.1.

Hope the above is OK. If you need anything more, please let me know.

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 22, 2008 12:55 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Use a CMTTransactionFactory and start a transaction before making a call to hibernate. Starting a transaction can be with container settings such as EJB transactions, Spring transactions, or simply a user transaction started transaction.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.