Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help!!! Hibernate Transaction with Websphere

 
kalpana salve
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using CMT.


Transaction code is :


public void insertOrUpdate(ProcessInstance pi) throws HibernateException {
Session s = HibernateUtil.openSession();
Transaction tx = s.beginTransaction();
try {
s.saveOrUpdate(pi);
if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Inserted or updated
processInstance" + pi.getProcessInstanceId() );

tx.commit();
} catch (HibernateException he) {
...
}
finally {
HibernateUtil.closeSession(s);
}

Above code works fine with JBoss and Weblogic, but throws an exception with
WebSphere-
(net.sf.hibernate.transaction.JTATransaction Could not find UserTransaction
in JNDI )

What solution will allow me to support WebSphere?


Any..pointer... .

Thanks in advance

kalpana

I am using CMT.


Transaction code is :


public void insertOrUpdate(ProcessInstance pi) throws HibernateException {
Session s = HibernateUtil.openSession();
Transaction tx = s.beginTransaction();
try {
s.saveOrUpdate(pi);
if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Inserted or updated
processInstance" + pi.getProcessInstanceId() );

tx.commit();
} catch (HibernateException he) {
...
}
finally {
HibernateUtil.closeSession(s);
}

Above code works fine with JBoss and Weblogic, but throws an exception with
WebSphere-
(net.sf.hibernate.transaction.JTATransaction Could not find UserTransaction
in JNDI )

What solution will allow me to support WebSphere?


Any..pointer... .Very Urgent

Thanks in advance

kalpana
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You you definitely using a TxDataSource (Transaction Data Source) in WebSphere? To help debug, you might try adding code to lookup the UserTransaction manually (outside of Hibernate) to make sure WS is set up correctly in the first place. Try to isolate the problem inside or outside Hibernate so you know what needs to be fixed.

You might try posting this to the WebSphere-related forum.

Finally, "urgent" tends to stress people out which makes them not want to reply. Try not to add your stress to the people from whom you want to receive help.
 
Dave Clark
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you say that you're using CMT / Container Managed Transactions.

why are you calling beginTransaction() and commit() explicitly in your code then?
am I missing something??

cheers,

Dave
 
V Katiyar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say CMT, are you saying that there is a SessionBean with container managed transaction? Are you calling Hibernate from this session bean's business method? If there is a Container Managed Transaction active, then the name "java:/comp/jta/UserTransaction" or whatever it is, is not available in the jndi namespace in WebSphere. That is a WebSphere specific thing. Usually, if these methods need reference to utx(to check utx status for instance), it can access the UserTransaction ref via sessionContext.getUserTransaction. But Hibernate may not know to do that.

When Hibernate does a jndi lookup for "java:com/jta/UserTransaction" from session bean method with CMT, it is going to fail in WebSphere. That might be your problem. Trying changing the session bean to Bean managed transaction, if you wish to lookup UserTx, then begin and commit your own transaction while interacting with Hibernate.

Good luck.
 
V Katiyar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, I am probably wrong. If it is a session bean with Container Managed Transaction, then session.beginTransaction() will start a nested transaction. I don't know if that will work in WebLogic or JBoss (you are saying it does), because I don't know if nested transactions are supported in Weblogic or JBoss.

Maybe Hibernate looks up java:comp/jta/UserTransaction in beginTransaction implementation and does utx.getStatus and runs with an existing active transaction in the CMT case or starts a new one if no tx is active. That might explain why your code works in WebLogic and JBoss. But fails in WebSphere because the lookup fails.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic