-->
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.  [ 1 post ] 
Author Message
 Post subject: Incomplete rollback in hibernate
PostPosted: Fri Feb 27, 2009 7:20 pm 
Newbie

Joined: Fri Feb 27, 2009 7:14 pm
Posts: 1
Need help with Hibernate? Read this first:

We have DAO class which does multiple inser/update in single transaction.If one of the insert/update fails it doesn't rollback the earlier succesful insert.

Suppose object 1 is inserted successfully and object 2 gets stale object exception the tx.rollback doesn't object 1 from database .Changes gets commited even though auto commit mode is false.


Please HELP!!!

public void saveUpdate(List list, Session session) throws Exception
FlushMode flushMode = session.getFlushMode();


try {
session.connection().setAutoCommit(false);
logger.info(" auto commit mode : " + session.connection().getAutoCommit());
} catch (HibernateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

Transaction tx = null;

try {

session.setFlushMode(FlushMode.COMMIT);
tx = session.beginTransaction();



for(Object obj: list){


session.saveOrUpdate(obj);




}


session.flush();
tx.commit();
tx = null;


} catch (RuntimeException e) {

if(tx.isActive()){
tx.rollback();
session.close();
session = HibernateUtil.getNewSession();
}


throw e;
} finally{
if(session != null){
try {
session.connection().setAutoCommit(true);
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
session.setFlushMode(flushMode);
}
}


}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.