Hibernate version:
1.2.0GA
Name and version of the database you are using:
Oracle 10g
I'm building an AJAX web application with NHibernate. For the client-server communication, I'm using a library called JSON.Net (javascript object notation). For most of what I'm doing, this works fine. However, when doing a db update, like this:
Code:
Document record = (Document)session.Load(typeof(Document), id);
// make some changes to record
session.Update(record);
UpdateResponse response = new UpdateResponse();
response.Success = true;
response.Document = record;
// call JSON.Net's SerializeObject(response) to send object data back to client in text format
I'm having problems, because now the record object isn't my plain-old object, it's a DynamicProxy object, and the serializer chokes on it (self-referencing loops with the Assembly and Module information that's included).
I've tried working around this by changing this line to:
Code:
response.Document = (Document) record;
and also
Code:
response.Document = record.Clone();
Neither of these work. (The Clone method is basically implemented as return this.MemberwiseClone()).
I've also tried just skipping the return of the updated record to the client, and forcing the client to reload the data in a separate server call, but this sometimes I get the DynamicProxy object back even without doing a db update first. It's this situation that has become the real showstopper.
So my question is, is there a way to force NHibernate to return the POCO class. Is there something similar to NHibernateUtils.GetClass that will do it for me? Or does someone have any better idea on how to not get the proxy object?
My only other solution is to re-write significant amounts of the JSON serializer, and even then I'm not sure where to begin.
Thanks