Hibernate version:
2.1.x
Hi.
I got stuck in a problem. I have an object X that I must implement a rule that checks if exists an object Y (unrelated to X) with some conditions each time object X is updated, to calculate one of the fields, and in some cases make a change back in object Y.
First I tried to build a routine in the
onFlushDirty method, which seems to be the right logical place to change the "currentState".
But I can't access a Session inside the Interceptor , right ?
So I cannott select Y object, and even if I write down an Interceptor with a Session property, it will not be able to change Y objects.
Quote:
"The Session may not be invoked from a callback (nor may a callback cause a collection or proxy to be lazily initialized)."
This is something that makes the access to any collection inside a callback
very dangerous! It may be not initialized by caller system, and them you got an error. Does onFlushDirty works only to simple check if a property is valid? Well, anyway, object Y is not related to X and I can't access it by lazy collection.
So I tried the LifeCycle , but as I expected, the onUpdate method is not called when an object is already in the session.
The only place where I can put this logic is outside the Hibernate event system. But them I will have to remember to call this logic in every subsystem that perform updates in the component. This is pain when you have to create a pattern of work to other enterprises.
Or I may write a layer over the session.update/save/delete to done this before. In this case, the LifeCycle/Interceptor will be useless, except for auditing and loging logic.
What I reaaaallllyyy dislike about hibernate is this Interceptor architecture, that intercepts all changes in all objects in the same place. It will be more organizated to have an interceptor class for each class (or interface), and one that can acess the Session like in LifeCycle.
Is there something I'm doing wrong ?
What about hibernate 3, it will address this kind of limitation with virtualization?
Thanks