-->
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: Initiate a change as a result of another
PostPosted: Fri Nov 14, 2003 12:54 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
Whenever a specific change occurs to one of my domain objects I want to be able to make another change. As an example, I have an object that has a set of states that are a part of a relationship with other objects. However, I also need to maintain a state that takes into account all the states for the relationships.

Currently, I am just loading the object and generating the state on the fly. What I would like to do is update the state whenever one of the relationship states change. So far I can think of two places to do this:

1. When the state for the relationship is changed, also update consolidated state.

2. Use an interceptor. When save() is called, make the update.

Option 1 doesn't seem optimal, because this value will be set whenever I get the object back from Hibernate. For read only operations, I don't want to make a change to the database.

Option 2 seems like a better approach. However, my understanding is that this would only be called after a save(), so I might have a stale consolidated state for a period of time.

Is there yet a better approach? At worst, I can always call save in the DAO when it makes an update to the relationship state for the domain object. If there is a better solution I'd love to use it though :).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 1:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Did you look at Interceptor.onFlushDirty(...) ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 3:04 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
I created a test case to test out Interceptor.onFlushDirty(). It appeared to never get called, which surprised me. However, I do see onSave() getting called when I tell Hibernate to save my object.

I wasn't quite able to grasp exactly when .onFlushDirty() gets called, so it is quite possible I am not using this correctly. When should .onFlushDirty() get called?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 3:08 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
Also, it does look I really want to be hooking on .onFlushDirty() because I can compare the current state against the previous state. I imagine this is what you were getting at. However, I am not sure how to get that method to be called.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 4:04 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
I did some digging and discovered that it is expected behavior that .onFlushDirty() is not called when a collection is modified, which is exactly the case in my situation.

That said, I also read about an incident in sourceforge tracking this issue for Hibernate 2.1. However, it looks like the sourceforge bug tracking is no longer used, but JIRA is instead. I only found two issues regarding .onFlushDirty(), neither of which addresses the collections issue.

Did this fall off of the radar? Should I file an enhancement request?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 5:11 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
I found a somewhat elegant alternative to using an interceptor. Basically, I made the set package private and only allow clients to manipulate it through another method (setStateOnSystem). This allows me to hook the way I wanted to.


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.