pupsnow / dphibernate

Automatically exported from code.google.com/p/dphibernate
0 stars 0 forks source link

Saving of POJO with lazy relationship resulting in Foreign key exception. #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have 2 Hibernate Pojo's named "Parent" and "Child".  Parent lazily loads
its relationship to Child.  When I retrieve a Parent in ActionScript the
object has a relationship to the Child proxy.  If I change an attribute on
Parent and then attempt to perist the Parent object, I get a foreign-key
exception because the id of the Child object is 0 when the save is
attempted on the sever (correcsponding to the NaN value on the ActionScript
proxy).  It appears that when the remote call to save the Parent is made,
an attempt to initialize/load it's Child object from the remote server is
made.  However, prior to completing the initialization the call to the
Remote save method is made sending a Parent object with an uninitialized
Child.  It seems like this might be a result of the fact that the remote
calls are asynchronous and are executing in parallel rather than serially.

Have you seen this before.  Any insight would be helpful.

Thanks,

Dave

Original issue reported on code.google.com by dboard...@gmail.com on 25 Sep 2008 at 7:39

GoogleCodeExporter commented 9 years ago
I think problem might be the way you save the object. I presume you use your 
own save method and you send the object to be persisted to the server.

From what I understand dpHibernate doesn't have a custom serializer to 
serialize the object sent from flex client, therefore when you send an object 
via a service call it tries to serialize whole object tree. That initiates lazy 
load requests made from flex client but before it gets the results object is 
sent to the server with proxies in place of lazy loaded "parent".

Solutian is: do not send any object through custom services instead use the 
method demonstrated in lazy overflow example. (i.e. object.save()) This method 
sends the proxy information of the object to be saved and an array containing 
the changes made to it. Therefore it won't cause any of the probkems mentioned 
above.

Hope it helps.

Umut

Original comment by uo1979 on 7 Feb 2011 at 4:37

GoogleCodeExporter commented 9 years ago
As Umut mentioned, persistence is handled through change messaging, instead of 
serializing the object graph.

Original comment by martypit...@gtempaccount.com on 15 Mar 2011 at 3:20