-->
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.  [ 4 posts ] 
Author Message
 Post subject: Container-mamaged transactions supported by Hibernate?
PostPosted: Fri Jun 04, 2004 2:19 am 
Newbie

Joined: Fri Jun 04, 2004 2:10 am
Posts: 2
I am new to Hibernate. After read the doc, I like it and want to use it in our project.

My question is:
I want to use container-mamaged transaction, can Hibernate support it? or where to find the resources about it?

I browse the forum. I find that the transaction is started/commited/rollback by the codes in the post.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 04, 2004 4:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, you can, read the reference documentation.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 4:47 am 
Newbie

Joined: Fri Jun 04, 2004 2:10 am
Posts: 2
Thanks a lot for the reply.

I read the reference recently. I want to confirm the following thing:

(1) when coding in a session bean with container-managed tranaction, I just return from the methods when everything is fine, or call EJBContext.setRollbackOnly() when I want to rollback the tranaction.
Can I still do it in Hibernate the same way as I did before?
I means whether the following code in a session bean is still correct:
Session hibernateSession = null ;
try
{
hibernateSession = sessionFactory.openSession();
C c = new C();
c.setAddress("foo bar");
s.save(c);
} catch ( Exception e )
{
ejbContext.setRollbackOnly() ;
} finally
{
if ( s != null ) s.close();
}
Note that I do not call begin*() to start a transaction. I hope Hibernate will enlist the global transaction managed by EJB container.

(2)Can I open a session in each DAO( i.e, every dao has a call to openSession() )? These DAOs participate in the same transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 6:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have to explicitly flush the session when using CMT


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