-->
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.  [ 2 posts ] 
Author Message
 Post subject: HibernateDAOsupport - TransactionControl
PostPosted: Tue Aug 08, 2006 4:34 pm 
Newbie

Joined: Tue Aug 08, 2006 4:24 pm
Posts: 1
Spring provides HibernateDAOSupport class from which we extend our DAO class.

If I want to update 2 tables in one transaction using my DAO class that extends HibernateDAOSupport can I do the following

this code is inside one of methods of my DAO class that extends HibernateDAOSupport
{

RPRTReferral ref = new RPRTReferral();
//
//
RPRTReferralComment comment = new RPRTReferralComment();
comment.setReferral(ref);

Transaction tx = getHibernateTemplate().getSessionFactory().getCurrentSession().beginTransaction();

getHibernateTemplate().save(ref);
if ( comment != null ) getHibernateTemplate().save(comment);

tx.commit();

}

Assume ref and comment are those 2 objects that i want to save in 1 transaction.
Both of my objects wil be under one transaction? [/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 4:48 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Yes, they should run in the same transaction. Now the only problem is that you are inserting business logic code into your DAO! ;D


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