-->
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.  [ 3 posts ] 
Author Message
 Post subject: Post-load initialization of an entity
PostPosted: Thu Nov 15, 2007 5:03 am 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi - I have a web application which is using a NHibernate 1.2 for its datalayer.

I have an entity reresenting users, but the database entity only contains a username. The username can be used to perform a lookup in Active Directory to retrieve the rest of the user information - firstname, surname, email, etc.

I would really like some way of running a "post-hibernate-load" action which will be looking up the remaining information in Active Directory.

I have investigated the ILifeCycle interface, but that would cause my domain object to be polluted with NHibernate, something that I must avoid.

Looking at the IInterceptor it seems that here I only have access to a "before-hibernate-load".

Any suggestions/strategies would be appreciated.

Cheers,
Thomas


Top
 Profile  
 
 Post subject: Re: Post-load initialization of an entity
PostPosted: Thu Nov 15, 2007 8:42 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
thomask wrote:
Looking at the IInterceptor it seems that here I only have access to a "before-hibernate-load".


The IInterceptor will work for you. I have used this type of approach in the past. Not for the exact reason you state, but we did use it to populate parts of an object from another source besides the main NHibernate query/load process.

The method you are looking for is the OnLoad method. It should look something like this:
Code:
public bool OnLoad(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)


Basically you have the entity being loaded (which would be your user object). You also have the id used to load the entity (probably what you need), you also have the state array which contains the property values being loaded from the database. For any property you need. Look in the propertyNames array, find the property you want and then use the index of that property on the state array to load the value you are looking for. If you need to know the NHibernate type that is also using the same index.

From that you should have all of the information you need to load things from Active Directory. This should work fine.[/code]


Top
 Profile  
 
 Post subject: Re: Post-load initialization of an entity
PostPosted: Thu Nov 15, 2007 4:10 pm 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi - thanks for the reply. :-)

I hadn't considered using the OnLoad method like that.

So what you are saying is that I retrieve my keys for the Active Directory by looking in the arguments for the OnLoad method, fill the supplied entity with the data and then return "true" to indicate that I modified the entity.

Correct?

Cheers,
Thomas


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