-->
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: JavaScriptSerializer and Proxy objects
PostPosted: Mon Oct 01, 2007 12:29 pm 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
Hi

I have a problem with Nhibernate, lazy loading and the JavaScriptSerializer that comes as part of the Ajax toolkit.
If I load an object which is marked as Lazy using something like session.load as in below:

Code:
session.Load<Type>(id);


Then it will not serialize due to a circular reference.
But if I use the code:

Code:
ISession session = _sessionManager.OpenSession();
string hql = string.Format("from {0} t where t.Uid = :uid", typeof(T).Name);
IQuery query = session.CreateQuery(hql);
query.SetGuid("uid", uid);
return query.UniqueResult<T>();


Then all is good. I am taking a performance hit on this and would like to be able to serialize proxied objects.

Is this possible or are there any steps I can take to help me achieve serialization?

has anybody been through this?

Cheers
Paul


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 12:38 pm 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
AFAIK, you cannot serialize stuff that has circular refererence. This has nothing to do with nhibernate.

2nd as you might know, session.load() only loads an uninitialized proxy. If you want an initialized proxy you need to use session.get() or Initialize method of NHibernate (or NHibernate.Utils can't remember)

Finally it is not a good practice to send your domain objects on the wire. You should instead use Data Transfer Objects which are merely wrappers to your domain entities. This will prevent circular references and you will have fully loaded object (including the lazy collections) depending on how you implement the DTO's.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 4:52 am 
Regular
Regular

Joined: Fri May 05, 2006 11:54 am
Posts: 51
If it was indeed a circular reference then how come when the object does not dervie from the proxy it serializes?

Also could you elaborate on this DTO wrapper.

I am not sure of how this would benefit things.

Thanks

Paul


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.