We would like to automatically balance our bidirectional associations in the setters.
That is, when we call a setter for one end of an association, if the value has changed,
we would like to update the other end.
However, when hibernate calls the setters (e.g., during find,save,update,factory creation)
we do not want to call the balancing code.
We are using hibernate version 2.1.8.
We had the idea, and also saw it in the FAQ, of creating new setters (setXxxByApp)
that do the balancing.
This will certainly work, but has a few drawbacks.
Are there any other ways to accomplish this?
One other idea is to wrap the hibernate query, save/update, and factory creation calls and
set global variables to indicate we are in hibernate code. Then the regular setters could
check these variables to determine if they should rebalance.
The main problem with this is for lazy initialization.
We have some big sets for which we do want lazy initialization.
Any other ideas/patterns for this?
-buddy
|