-->
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: Transaction rollback does not work iwth hibernate3
PostPosted: Wed Jun 06, 2007 3:25 am 
Beginner
Beginner

Joined: Sun Nov 19, 2006 6:18 am
Posts: 28
Hi,
Following iss my code snippet. I m trying to add 2 SmhostBean objects with id 1 and id 2. The id is the primary key here.

I m adding them in the same transaction.
But id 1 already exists in the Db.si its insertion the second time should throw an exception whithc it does. But what i obsever is that SmhostBean object with id 2 gets inserted.The roll back is not working.

Kindly help ...



Session session=HibernateUtil.currentSession();
Transaction transaction=session.beginTransaction();
SmHostBean hostBean=new SmHostBean();
hostBean.setId(2);
hostBean.setIpaddress("22");
hostBean.setPort("22");
session.save(hostBean);
hostBean=new SmHostBean();
hostBean.setId(1); //this id already exists in the DB
hostBean.setIpaddress("11");
hostBean.setPort("11");
session.save(hostBean);
try{
session.flush();
transaction.commit();

}catch (Exception e) {
transaction.rollback();
}


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.