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.  [ 10 posts ] 
Author Message
 Post subject: PostLoad, AfterLoad
PostPosted: Tue Jun 06, 2006 11:49 am 
Newbie

Joined: Tue Jun 14, 2005 6:45 pm
Posts: 5
I've scoured the web and haven't found a reference on how to do this.

I'd like to intercept an entity after it's been hydrated by nhibernate and modify the IsDirty flag of the entity.

My problem is I have an entity and in each setter I set the dirty flag for the entity. This allows presenter objects to enable buttons on the ui to let the user know that they can Save the object.

The only other way to do this would be to implement ILifecycle right? And that is discourage so it doesn't seem like the solution.


Top
 Profile  
 
 Post subject: Can't be done?
PostPosted: Mon Jun 12, 2006 10:56 am 
Newbie

Joined: Tue Jun 14, 2005 6:45 pm
Posts: 5
Usually when nobody replies it's because it cannot be done... is this where we are at?


Top
 Profile  
 
 Post subject: Re: PostLoad, AfterLoad
PostPosted: Mon Jun 12, 2006 1:54 pm 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
choenes wrote:
I've scoured the web and haven't found a reference on how to do this.

I'd like to intercept an entity after it's been hydrated by nhibernate and modify the IsDirty flag of the entity.

My problem is I have an entity and in each setter I set the dirty flag for the entity. This allows presenter objects to enable buttons on the ui to let the user know that they can Save the object.

The only other way to do this would be to implement ILifecycle right? And that is discourage so it doesn't seem like the solution.


But if you implement the IInterceptor, it gives you those kinds of hooks.. why is that not what you want?


Top
 Profile  
 
 Post subject: IInterceptor can't be used for this
PostPosted: Wed Jun 14, 2006 3:51 pm 
Newbie

Joined: Sat Feb 11, 2006 12:11 pm
Posts: 7
This is exactly my situation too. IInterceptor does not help because it doesn't offer a PostLoad event where you can access the hydrated entity. I only see two solutions to this problem: 1) have your entities implement ILifeCycle 2) in mappings tell NH to access the class fields instead of properties.

I didn't like any of these solutions so I choose to set the flag to false manually after the load. For me it works because I have a service layer that can do this before returning the objects to clients. You could do this also in a Dao base class.

I understand that Hibernate 3.0 gives you the possibility to handle the PostLoad event by offering a new system of events. Maybe we'll have this in NH 1.2.0.

Anyone, please correct me if I'm wrong (I still hope there is a more ellegant solution...)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 3:32 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
Oh yes, you guys are right. This is indeed a problem.
I use the instantiate hook to set a boolean (but it's not hydrated yet), so later on, I will call a method on each object that checks for this bool and act upon it.

Sergey is always in for implementing h 3.0 things, so you might want to make an issue in jira and point to the h 3 implementation. I would vote for it ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 5:35 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
This is exactly what I need, any news on this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 8:49 am 
Beginner
Beginner

Joined: Mon Mar 26, 2007 5:47 am
Posts: 22
Me too I could use this... any news? What about the 1.2 version?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 10:17 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 12:35 pm
Posts: 24
I had a need for OnPreLoad and OnPostLoad in both ILifeCycle and IInterceptor. I sent the patch to jira.

http://jira.nhibernate.org/browse/NH-970[/url]


Top
 Profile  
 
 Post subject: OnPostLoad
PostPosted: Tue Sep 11, 2007 12:47 am 
Newbie

Joined: Thu May 19, 2005 9:18 pm
Posts: 2
I followed the above link, downloaded and compiled against the NHibernate 1.2GA but the OnPostLoad doesn't seem to be doing anything, is there something that I miss?

Cheers
Tien


Top
 Profile  
 
 Post subject: OnPostLoad
PostPosted: Tue Sep 11, 2007 2:06 am 
Newbie

Joined: Thu May 19, 2005 9:18 pm
Posts: 2
Please disregard the above as I found the answer myself

Cheers


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.