-->
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: Flagging an object for save/update
PostPosted: Wed Nov 15, 2006 6:03 pm 
Newbie

Joined: Wed Nov 08, 2006 11:29 am
Posts: 3
Using Hibernate3:

I'd like to be able to somehow flag objects to be saved/updated and have them only saved/updated if that flag is set.

My idea is to overwrite the findDirty method of EmptyInterceptor and simply check the given Object for a "flag" (and then marking dirty or not), but since that object is of type Object, I cannot access any data members or methods of my own types.

Is there a way to do this? Can someone at least point me in the right direction?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 6:51 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
1) Hibernate already does this for you with the unsaved-value attribute of the identity. Maybe you can leverage that?

2) If you need another flag to indicate save status to an interceptor, simply cast the object passed to the interceptor to the proper type and you should have access to your public methods (of course, as long as it is that object type, which you should check for).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 7:02 pm 
Newbie

Joined: Wed Nov 08, 2006 11:29 am
Posts: 3
I'll look into (1). So far it looks promising.

(2) isn't an option because the package that I'm implementing the interceptor in cannot know about the object types it will deal with.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 7:04 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
For (2) you can always use reflection to determine if the aforementioned property exists and get its value.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 9:40 pm 
Newbie

Joined: Fri Jul 28, 2006 10:53 am
Posts: 15
(1) would seem to only work for new objects, not ones that just need updating (you can't really update an object that has a null id, obviously). That would also be helpful for an application I'm working on too; its workflow is like so:

1. User loads the page, with a Hibernate session created and subsequently closed to read in all the data objects
2. User modifies the data on the page
3. User click save, with a Hibernate session created that calls update(...) on every data object

Obviously that becomes very inefficient the more data objects there are. I could have two separate lists of data objects, ones that haven't been modified and ones that have, but that just seems very clunky; there has to be a better way. If I have a single session persistent through the entire "conversation" and just use multiple transactions, would that allow me to skip the update step (when I want to save, I just start a transaction, call session.flush, and then commit)? I've read through the documentation and the articles on the website, but I haven't found anything yet that specifically states whether or not Hibernate keeps track of object changes in-between transactions on a single session.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 2:33 pm 
Newbie

Joined: Wed Nov 08, 2006 11:29 am
Posts: 3
IG -

I have since discovered what you said about (1). So that's no good.

My application's flow is very similar to what you describe. The main difference is that the user can load multiple pages and have them in various stages of edit. Then when a user hits the "submit" button on any one page, they all get updated.

Obviously, I need the update to only happen for the page they hit the "submit" button on.

Solution pending...


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.