-->
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: NHibernate 1.2 class lazy="true" and WCF Serializa
PostPosted: Wed Aug 15, 2007 11:10 am 
Newbie

Joined: Thu May 31, 2007 12:28 am
Posts: 2
Hi
We migrated our system to NHibernate 1.2GA from NHibernate 1.0.3
I have modified class definition in the mapping file for the business entities to lazy="true" and I started getting errors and I tried so many ways and could not be able to fix it. Could anyone please help me in this.
If set lazy="false", things start working, but unfortunately we have to set it to true as per the architecture.
Thanks
Rama.NET
(Currently breathing .NET)

Here is the class definition
<class name="Domain.LocalAgencyEntity, DataAccess" table="Zipcode" lazy="true" select-before-update="true">
..........
</class>


Here is the exception message:

There was an error while trying to serialize parameter http://tempuri.org/:ExecuteServiceResult. The InnerException message was 'Type 'CProxyTypeDomainLocalAgencyEntityDomain_NHibernate_ProxyINHibernateProxy1' with data contract name 'CProxyTypeDomainLocalAgencyEntityDomain_NHibernate_ProxyINHibernateProxy1:http://schemas.datacontract.org/2004/07/' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.

Here is the complete stacktrace:
<StackTrace>
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
at System.ServiceModel.Channels.MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)
at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
at System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestContextBase.Reply(Message message)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessageCleanup(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.Set(Item item)
at System.ServiceModel.Channels.InputQueue`1.Dispatch()
at System.ServiceModel.Channels.InputQueue`1.OnDispatchCallback(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.WorkItem.Invoke()
at System.ServiceModel.Channels.IOThreadScheduler.ProcessCallbacks()
at System.ServiceModel.Channels.IOThreadScheduler.CompletionCallback(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 11:27 am 
Newbie

Joined: Mon Aug 13, 2007 8:49 pm
Posts: 9
I'm actually going through the exact same process that you are, trying to load information via NHibernate to a service.

Since you are instructing WCF to send your domain objects over the wire, you CANNOT send over proxies generated by NHibernate via the lazy="true" attribute. These proxies support the lazy loading ability by not actually hitting the database until you touch one of the properties. At that point, the object calls NHibernate to hydrate itself with the actual values and is loaded. (Remembering that the proxy object is the subclassed instance!)

Now comes the tricky part. Depending on your Service Operation [OperationContract], You must either set those properties to NULL if you don't need info in them, OR you must touch the property to load the entity values, and REPLACE that property with a freshly built copy of the values. In other words, you'd hit "object.LegalAgencyEntity.Id" to have the proxy load up the instance values, and then set object.LegalAgencyEntity = new Domain.LegalAgencyEntity() with all the values copied from the proxy into the actual instance.

Personally, I'm finding that its not a great idea to try to send out your DOMAIN objects over the wire, but to actually send out DATA CONTRACT over the wire. There's a fairly large difference here. Which implies that you're actually going to have to think about your data contracts, and make them distinct from your domain objects.

Your DATA CONTRACT is what that service can return. Since you're using lazy loading, data contracts in services cannot support that.

I'm planning on writing a blog post about this issue on http://geekswithblogs.net/ensoftBlog/[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 11:06 am 
Newbie

Joined: Thu May 31, 2007 12:28 am
Posts: 2
Hi Eric
Thanks for the fast reply. I hope you will blog about this as soon as possible. :-)
--Rama--
(Currently breathing .NET)


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.