-->
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.  [ 1 post ] 
Author Message
 Post subject: Intercepting a change to perform queries in the session
PostPosted: Fri Feb 11, 2005 8:47 am 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
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

_________________
Alexandre Torres
--------------------


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.