-->
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: Persist Only Explicitly Saved/Updated Objects
PostPosted: Mon Mar 28, 2005 4:22 pm 
Newbie

Joined: Fri Feb 11, 2005 10:23 am
Posts: 4
Location: Developer
Hello all,

The way Hibernate works generally is that all objects returned by the Hibernate engine are added to the Session cache and when flush is called at the end of the session any dirty objects are automatically persisted.

This is a great feature of Hibernate, but for my application it is not desireable. Basically, I am using my persistent entity objects as user editable "value objects" in a Spring/Tapestry application. Because the the actual persistent objects are out there and more or less exposed to Users, I want to only update objects which I explicity call save or saveOrUpdate on.

So if the session opens and objects A and B are retrieved from the store and both are changed somehow I want to be able to call

Code:
session.save(a);
session.flush();


and know that B wont be persisted.

I know that I can do something like evicting all objects from the session cache whenever they are returned by my DAO methods. So my questions are:

1) Is that the best way to do it?
2) Are there any heinous side effects to calling Session.clear() all the time?
3) Is there a way I can stick this in an interceptor or something so I don't have to call Session.clear() manually everytime I retrieve something from the db? I guess the desired behavior is that Hibernate always gives me back detached objects.

I'm using the session-per-request model.

Thanks to everyone in advance,

Bobby

Hibernate version: 2.x


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.