-->
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.  [ 6 posts ] 
Author Message
 Post subject: Transactions and rollback
PostPosted: Fri Feb 08, 2008 9:33 am 
Newbie

Joined: Wed Jan 09, 2008 7:16 am
Posts: 7
I am writing a web application which uses hibernate.

I've figured out that it is going to change objects only in a few places which I can handle specially.
In most cases, it would not modify objects during request handling.
In some cases it would modify objects, but I don't want those changes to be persisted - sort of preview mode, I want to change object state, display it for confirmation but don't persist yet.

Here are questions.

How WTFish is using rollback() to cancel changes which I did but don't want to persist? Is rollback() intended to be used only when something really wrong (like exception) occurs, or it can be used just to say "nevermind, forget about it"?

Can I somehow state that I'm not going to make any changes, to skip dirty checks and possibility for some changes to slip in due to some occassional bugs in code?

Can I rollback() transactions which never made any changes to DB instead of committing() them, or that would be a major WTF?

Maybe I should consider anything else here?


Top
 Profile  
 
 Post subject: Re: Transactions and rollback
PostPosted: Fri Feb 08, 2008 1:11 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I wouldn't play around with roll back since it could and would have side effects. However, you can evict all objects you don't want to be synchronized with database from a session's memory and that will do the trick for you.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 4:01 pm 
Newbie

Joined: Wed Jan 09, 2008 7:16 am
Posts: 7
Can you be more specific about side-effects I might get?

I would go that evict route, but unfortunately evict doesn't work if object is mapped with natural id. Now I'm considering having those natural-ids removed, remapped as plain properties.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 4:05 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Ilyak wrote:
Can you be more specific about side-effects I might get?

I would go that evict route, but unfortunately evict doesn't work if object is mapped with natural id. Now I'm considering having those natural-ids removed, remapped as plain properties.


A transaction might be synchronizing multiple resources. In this case your use case may cause other use cases to fail. This is usually a good failure opportunity for a software system that evolves through time. It makes it almost impossible for other developers to respect your decision since transactions have a broader usage.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 4:21 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
There are two thing you can also do:

1- Session.clear() removes everything in a session's memory which means nothing will synchronized with database and you don't have to worry about natural ids.

2- You can set Session's flushMode. HB document suggests a MANUAL mode for read only accesses.

I hope either of them do the trick for you.

Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 4:53 pm 
Newbie

Joined: Wed Jan 09, 2008 7:16 am
Posts: 7
That "two things" look very heplful. I will surely try them. Thanx for your support.


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