-->
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: doubt in rollback
PostPosted: Mon Dec 10, 2007 11:02 am 
Newbie

Joined: Mon Dec 10, 2007 10:47 am
Posts: 3
Location: India
hai,

i have doubt in rollback concept.pls clear my doubt.

first i saved the data in the session, then i rollback again, sothat the data are not stored permenently in the database. its workking fine.

but my question is the data are not rollback in the class ie(User class).

when i print the last inserted id from the class, it print last inserted id, but that id not present in the database. bcz it already rollback. so how to rollback in the class also



see the code for clear description


User user = new User();
user.setFirstname((String)addContactForm.getFirstname());
user.setLastname((String)addContactForm.getLastname());
user.setEmail((String)addContactForm.getEmail());
session.save(user);

session.getTransaction().rollback();
System.out.println(" last inserted id"+user.getId()); // from user class.


Top
 Profile  
 
 Post subject: Re: doubt in rollback
PostPosted: Mon Dec 10, 2007 10:29 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
pearlkumar wrote:
session.getTransaction().rollback();
System.out.println(" last inserted id"+user.getId()); // from user class.



It must have something to do with your database. IDs can not be rolled back since most of them are sequential. So lets say you use n and you want to revert back. However, n+1...n+m might have been used in this while and it is not a trivial task to put n in queue for the next id generation and make sure the one after n is n+m+1. You will have to implement your own id generation mechanism if you want this to work but it will be quite complicated. That's what I think though.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 12:12 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
>> when i print the last inserted id from the class, it print last inserted id, but that id not present in the database. bcz it already rollback.

That row never got inserted in first place.
Identifier is fetched on save ( session.save(user))
The row gets inserted only on a flush. (directly or otherwise, say through commit )
Database transaction rollbacks do not rollback sequence fetches.

>> so how to rollback in the class also

Hibernate Models are POJOs. They can be ( and are often ) used seamlessly with other classes and objects.
So, it's fair on Hibernate's part not to reset the entries in our POJO.

---------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 5:25 am 
Newbie

Joined: Mon Dec 10, 2007 10:47 am
Posts: 3
Location: India
pramodkp wrote;


Hibernate Models are POJOs. They can be ( and are often ) used seamlessly with other classes and objects.
So, it's fair on Hibernate's part not to reset the entries in our POJO.


reply from pearlkumar



if any other way to reset the values in the POJOs. or Not possible to reset in the POJOs.

Thanks


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.