-->
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: Lazy serialization?
PostPosted: Thu Feb 01, 2007 1:06 pm 
Newbie

Joined: Thu Feb 01, 2007 12:50 pm
Posts: 4
Hi
I'm kind of a new user in Nhibernate and I've ran into a problem considering serialization. The database I'm working on will produce in the end parents containing children etc (multileveled tree), therefore the need to use Lazy = true (we don't want to load half the database for a single information, if needed). The problem is that at some point I have to serialize a part of the tree... and from what I understood serialization with lazy loading would be impossible. Has anyone had this problem before and is there any workaround this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 5:04 am 
Newbie

Joined: Sun Nov 05, 2006 10:19 am
Posts: 13
I'm interested also on this idea...But in my opinion it's impossible ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 5:44 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It should be possible, but you need to have the necessary libraries around when you deserialize the object. For example, serializing and deserializing in the same application works just fine.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 6:08 am 
Newbie

Joined: Thu Feb 01, 2007 12:50 pm
Posts: 4
I've done a little test (yes, in the same application), trying to serialize (XMLSerializer) a lazyLoading object that contains inner objects. The exception I got is

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: CProxyTypeMyNamespaceMyClass_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2 cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported()
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
...

Trying to work with BinaryFormatter serializes ok, but throws an exception when deserializing

NHibernate.LazyInitializationException: Could not initialize proxy - no Session.
at NHibernate.Proxy.LazyInitializer.Initialize() in c:\net\nhibernate\nhibernate\src\NHibernate\Proxy\LazyInitializer.cs:line 77
at NHibernate.Proxy.LazyInitializer.GetImplementation() in c:\net\nhibernate\nhibernate\src\NHibernate\Proxy\LazyInitializer.cs:line 240
at NHibernate.Proxy.CastleLazyInitializer.Intercept(IInvocation invocation, Object[] args) in c:\net\nhibernate\nhibernate\src\NHibernate\Proxy\CastleLazyInitializer.cs:line 59
at CProxyTypeMyNamespaceMyClass_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2.ToString()
...

As I said... I need a solution for lazyLoading (when lazy = false everything is fine, but the option is not acceptable)

Thx in advance,
Sirin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 7:54 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Ahh, XML serialization is an entirely different story. I assumed you meant standard .NET serialization. XML serialization has lots of limitations, not just proxies.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 10:17 am 
Newbie

Joined: Thu Feb 01, 2007 12:50 pm
Posts: 4
This may sound strange... but it's the client's idea and I had to ask: is there any way to programmatically change the lazy loading at runtime?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 12:22 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Technically, probably yes.
Practically, no.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 10, 2007 1:49 pm 
Newbie

Joined: Wed Feb 07, 2007 3:06 pm
Posts: 3
I am having this same issue? Is there another solution for XML serialization that supports proxies?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 10, 2007 1:49 pm 
Newbie

Joined: Wed Feb 07, 2007 3:06 pm
Posts: 3
I am having this same issue? Is there another solution for XML serialization that supports proxies?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 11, 2007 10:42 am 
Newbie

Joined: Thu Feb 01, 2007 12:50 pm
Posts: 4
@nolamonk (don't know if this helps.. but here it goes)
We're currently thinking about implementing the serialization ouselves... but one idea that came to us was to have 2 sessionFactory objects, one built from the normal config and the second one from a changed Configuration (modify the input stream to change all the lazy = true to lazy = false)...


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.