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.  [ 4 posts ] 
Author Message
 Post subject: Lazy Loading & .Net remoting - proxy problem
PostPosted: Fri Aug 15, 2008 4:54 am 
Newbie

Joined: Wed Aug 13, 2008 10:32 am
Posts: 3
NHibernate version: 2.0
I'm trying to find an elegant solution to our problem. We have a complicated domain model which is a nightmare unless we can set it to Lazy load. However our multi layer n-Tier architecture is using remoting between the Service and presentation Tiers which is causing even more problems.

The problem as I understand it is that the proxies that are generated by NHibernate to carry out the lazy loading at run tiime are not serializable.

I've scoured the net looking for an elegant solution but have so far only come across a couple of ideas but nothing concrete.

Has anyone got any real world solution to this problem? Have I missed something obvious or not?

Thanks in advance

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 15, 2008 10:07 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Our solution was to check if the property had been loaded from inside the getter. If it is not, you can either:

1. Throw an exception, assuming you know all the objects that need to be loaded for a screen. The screen designer should populate the necessary objects for that screen.

2. Have the object hit the service layer and lazy load the property transparently.

The more interesting problem to solve is transporting the NHibernate proxies. They don't play well with WCF.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 15, 2008 11:01 am 
Newbie

Joined: Wed Aug 13, 2008 10:32 am
Posts: 3
Thanks Mike

We have already looked at initialising all the required objects in the service tier, but this still leaves us with remoting proxies problem in you last point:

If object A has a relationship with object B and object C.

If we retrieve A and tell the initializer that we are interested in object B as well, what happens is that even though we are not touching the property getter for C at any point, when the object is serialized for remoting, an exception is thrown because the property getter for C is a non serializable proxy(breath).

I've seen a few ideas about generating our own proxies, but this is all new to me and I'm not entirely sure how to go about the whole thing or even if it solves our problem.

Cheers

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 15, 2008 12:14 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
In your getter, check if the proxy has been initialized. If the proxy has not been initialized return null, this is an alternative to throwing the lazy load exception.

Also, if you dont want to return null for uninitialized references you could handle it through custom serialization. Throw the lazy load exception for most cases, but when serializing return null.

This is how to do custom DataContract serialization.
http://msdn.microsoft.com/en-us/library/ms733064.aspx


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