rnmixon wrote:
1) Any time a Person or Branch gets updated I would put a condition in the onSave/onFlushDirty/onDelete methods to maintain a Set of all of the top-level parents (i.e. Corporate) that owned the children.
Where is this set kept? In the child as a transient?
rnmixon wrote:
2) Now in the postFlush methods I can see if there are any entries in the Set of affected parents. If so it looks like I have access to the top-level object, so I can do the summary traversal of the children, update the summary properties in the parent and issue an update (using a new temporary session of course).
How are you managing transactions - are the sessions (the original and temp) in the same transaction (using JTA or managing the JDBC connection outside of hibernate, for example), or is each its own transaction. Either way, I see potential issues...
rnmixon wrote:
My problem is it just seems like I'm doing the update twice.
Yeah, which is why I asked about transactions. If the main and temp sessions are different transactions, you may get deadlocks. If they're in the same transaction, you might be stepping on your own changes.
rnmixon wrote:
Also, my upper-level code loses track of the version number in my object. I hang on to the version number ot make sure users do not accidentally overwrite each other's updates unknowlingly.
I'm not sure what you mean when you say 'loses track' (or 'upper-level code' for that matter - you mean the application code that's calling hibernate originally?) How are you hanging on to the version number and what exactly is happening?
rnmixon wrote:
Does this make any sense? Are there other approches to consider?
Thank you - Richard
I understand why the interceptor was tempting. The thing that would make me nervous about it is (as alluded to above) you're changing an object that may have been changed in the transaction and you've got to do it in a different session, leading to the potential issues discussed above.
could you intercept the parents preFlush/findDirty and scan downward? the problem there would be knowing if a child changed without the previous value array. Lazy loading in during a flush might not be the best thing, either, but you might be able to get around that by detecting unloaded lazy collections...
Could the child dirty detection stuff put out an asynch message of some sort (JMS, for example) 'queueing' the update of the summaries? Kindof a heavyweight approach to it.
Alternatively, you could manage this in the application layer by having the parents listen for change events on their children. This may not fit with your domain model, and it would require that the whole graph be in memory. This last bit might be managable with lazy loading of parents, but that might not work with your application architecture (if you manipulate detached objects) and it might involve a lot of database overhead in large graphs.
well, there's some thoughts anyway. hopefully it at least gives you additional perspective.
-danch