-->
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.  [ 6 posts ] 
Author Message
 Post subject: Portable transaction API from CMT to plain Java?
PostPosted: Thu Aug 12, 2004 2:19 pm 
Newbie

Joined: Thu Apr 01, 2004 3:36 pm
Posts: 13
Location: New York
Hibernate version: 2.1.4

Code between sessionFactory.openSession() and session.close():

Code:
      dbSession = DataUtil.getSession(getHibernateConfig());
      dbTransaction = dbSession.beginTransaction();
      dbSession.save(event);
      dbSession.flush();
      dbTransaction.commit();
      dbSession.close();


Ok, I would like to be able to use the above code (or a better one) both with CMT and in plain java code. The following configurations failed:

    CMT with hibernate JTA transaction: Hibernate transaction looks in JNDI for UserTransaction, which is not available with CMT (al least in jboss). To put the UserTransaction in java:comp I would have to declare the bean with BMT but that opens a can of worms.
    CMT with hibernate JDBC transaction: Jboss rightfully complains that you are not supposed to commit in a CMT. But if I don't commit the transaction, then the code does not work in plain Java code


Has anyone else had/solved this problem? I would expect something like the hibernate transaction (magically?) detecting that it runs in a CMT environment and do nothing.

Would it be a solution not to use the Transaction object at all and just flush and close the session? Would session.close() commit the underlying transaction?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 2:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is exactly the right way. I just suppose you have not configured Hibernate correctly for CMT/Jboss. Most likely wrong TransactinMannagerLookup.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 3:00 pm 
Newbie

Joined: Thu Apr 01, 2004 3:36 pm
Posts: 13
Location: New York
Thanks Michel for the quick response. I was setting the property jta.UserTransaction instead of hibernate.transaction.manager_lookup_class. Setting the second works flawlessly.

I was trying to avoid appserver specific info in the hibernate config, but it's not such a big deal.

What about the second question? Is it OK not to use the transaction object at all? The transaction objects is useful when you want to have multiple transactions in the same session, but is it required even for just one transaction?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 6:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You should really always explicitly demarcate your transactions. Not doing so might only be useful in some _very_ exotic usecases, and if you _really_ know what you are doing.

So generally speaking, yes always use the transaction api.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 23, 2004 9:06 am 
Newbie

Joined: Sun Oct 03, 2004 9:00 am
Posts: 7
bcalmac wrote:
Thanks Michel for the quick response. I was setting the property jta.UserTransaction instead of hibernate.transaction.manager_lookup_class. Setting the second works flawlessly.

I was trying to avoid appserver specific info in the hibernate config, but it's not such a big deal.

What about the second question? Is it OK not to use the transaction object at all? The transaction objects is useful when you want to have multiple transactions in the same session, but is it required even for just one transaction?

Thank you.


Following is the configuration:

<!-- Transaction API -->
<property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="transaction.manager_lookup_class">
net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
</property>


but getting following error:

[10/23/04 15:58:34:356 AST] 6a2dede1 JTATransactio E net.sf.hibernate.transaction.JTATransaction TRAS0014I: The following exception was logged javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:".


Top
 Profile  
 
 Post subject: Hibernate transaction problems and solutions...
PostPosted: Thu Oct 28, 2004 12:34 pm 
Newbie

Joined: Fri Oct 22, 2004 9:27 am
Posts: 1
My E.I.S Tier is based on DAO Pattern, and every DAO object is using Hibernate to manage persistence on the database.

I


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