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.  [ 5 posts ] 
Author Message
 Post subject: Modify entity after load - now that ILifeCycle is gone
PostPosted: Mon Mar 05, 2007 7:45 am 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
I have an entity in a SQL database that is managed by NHibernate. This entity has a description attribute that is stored elsewhere and needs to be retrieved via a webservice call after loading the NHibernate managed entity.

What's the best way to implement this? Should I have the entity implement an "ILoadExternalData" interface and then check for the interface in the OnLoad method of the interceptor (although isn't this called before loading the entity)?

Or should I implement the "loadExternalData" method in every call to the DAO for this particular entity? (although that won't help when traversing associations to this entity from other entities).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 7:49 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, you should use the interceptor. It's called after the values of the entity's properties are loaded, but before they are injected into the entity. You can modify the values or the entity itself.

By the way, ILifecycle isn't gone yet, it's just deprecated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 8:01 am 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
sorry, i didn't mean "gone, never to be seen again", but "gone, it's not recommended that you use it" :)

while I've thought of an approach, I'm not happy with it as it would lead to coupling the domain layer to the DAL, and would like suggestions on how to avoid this.

I was thinking that the Interface could implement a Load method, but then the domain entity would need to implement the Load, calling a method on its own DAO (or IDAO) or similar. However I'm trying to avoid my domain layer having to know about the DAL.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 2:40 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
Ok, I've given in and have decided to allow my entities to know about my DAL, and I'm using dependency injection to provide my entity with an instance of the DAOFactory in the OnLoad of the IInterceptor, if the entity implements an IUsesDAOFactory interface.

I was also planning on having an "ILoadExternalData" interface, implementing a "Load" kind of method so that after I've injected the DAOFactory into the entity I can call the LoadExternalData() method on it, and the method can implement it's own calls to the relevant DAOs to populate related entities that come from elsewhere (i.e. another database/session). However to populate related entities, it will need to use values of attributes on itself, which I assume can only be provided using the object[] state and string[] propertyNames collections made available in the OnLoad method of the IInterceptor. Therefore I assume that my Load method on the interface will have to be LoadExternalData(object[] state, string[] propertyNames).

this is starting to look messy. Is there an easier way to do this, or am I being too pedantic in saying it's messy, and it's actually alright??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 3:59 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Why would using an interceptor couple your entities to the DAL if the interceptor was designed precisely to avoid that? In the interceptor's OnLoad method, you would call a method on the entity being passed in that would load the necessary data, and that's all, your entity doesn't need to know about NHibernate at all.


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