-->
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: Hibernate & JTA
PostPosted: Thu Aug 28, 2003 6:23 am 
Hello,

Can someone give me an example how to use Hibernate with JTA in EJBs.

Here is my EJB code (EJB is controlled by containter, method transaction attribute is "Required"):
---------------------
Session session = Application.getInstance().getHibernateSession();
System.out.println("class:"+session.getClass());
session.setFlushMode(FlushMode.COMMIT);
Utilisateur user = new Utilisateur();
user.setDn("mydn");
user.setNom("mynom");
user.setPrenom("myprenom");
user.setSmtp("mysmtp");
Long id = (Long) session.save(user);
System.out.println("save");
session.flush();
session.close();
-------------------------
I don't understand, why session.flush() commits the tranasction...
I create JTA transaction in my client code :
UserTransaction userTran =(javax.transaction.UserTransaction)ctx.lookup("javax.transaction.UserTransaction");
userTran.begin();
---EJB code call

Thanks!


Top
  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 6:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
flush() certainly does NOT commit the transaction!


Code:
session.setFlushMode(FlushMode.COMMIT);



That looks kinda wrong. There is no Hibernate Transaction, so FlushMode.COMMIT is equivalent to FlushMode.NEVER. Still, you call flush() manually, so it should not be a problem.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Thu Aug 28, 2003 9:35 am 
gavin wrote:
flush() certainly does NOT commit the transaction!


Code:
session.setFlushMode(FlushMode.COMMIT);



That looks kinda wrong. There is no Hibernate Transaction, so FlushMode.COMMIT is equivalent to FlushMode.NEVER. Still, you call flush() manually, so it should not be a problem.


That's why I ask this question :) As I found in Hibernate docs, flush must not make commit() in JTA mode. But it does :( . May be there's something wrong with my hibernate configuration? (I do have <property name="jta.UserTransaction">javax.transaction.UserTransaction</property> in my the property file).

My idea : to have multiple EJB methods that will create its own transaction if called alone or use transaction that was created before...

PS. i tried not to use FlushMode.NEVER - it changes nothing :(


Top
  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 1:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Are you certain auto-commit is disabled for the jdbc connection? If not then flush would cause a commit. This would commit only the jdbc connection, however, and not the UserTransaction.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
Are you certain auto-commit is disabled for the jdbc connection? If not then flush would cause a commit.


No. Hibernate disables auto-commit.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.