-->
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: how to manage Transaction ?
PostPosted: Mon May 18, 2009 2:30 am 
Newbie

Joined: Thu Jan 15, 2009 9:54 am
Posts: 12
Hi,
I m using Spring with Hibernate by extending the HibernateDaoSupport class.
I have a method which accepts a List Collection as the parameter.
I m iterating over the List and updating my database as follows:

//////////////////////////////

Iterator iterator = cabRequests.iterator(); //cabRequests is a List object containing cabRequest Objects.
CabRequestDTO cabRequest = null;
try {
while( iterator.hasNext() ) {
cabRequest = ( CabRequestDTO ) iterator.next();
getHibernateTemplate().update( cabRequest );
}
}

//////////////////////////////

Assume, the List has 5 objects to update.

if there is any problem in the third object, an exception is thrown.
Result is : Object 1 and Object 2 is updated while Object 3, 4, 5 is not updated.

My Requirement: I want to update all the objects in the list in one stroke.
if there is any problem in between, i want to rollback or Undo all the updates.
in Brief: i want to update All or Update none.

Pls help as i need to deliver this asap.

Thanks in Advance.

Abid


Top
 Profile  
 
 Post subject: Re: how to manage Transaction ?
PostPosted: Mon May 18, 2009 8:49 am 
Newbie

Joined: Wed May 06, 2009 6:10 am
Posts: 4
Code:
<tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
           <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
</tx:advice>


this is the property that you want. if you use like this all queries use same transaction and rollback in any error. if you use REQUIRES_NEW all queries use their own transaction.


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.