This will probably be very useful in situations where we do not have full control of the object in question. For example Axis is a very good framework for implementing web services, as well as Java -> XML & XML -> Java binding. However without modification of Axis, the returned Java object will always be a new object (as far as Hibernate is concerned). If we are using long running async messaging with Axis we may not even have the original object to modify. Thus having the saveOrUpdateCopy method will allow for directly saving the copy with the updates to the database. The saveOrUpdateCopy is in-efficient compared to saveOrUpdate, but does the same work that I would have to do in order to save the updated data to the DB. And as always the more you can let a framework do the better.

Yes, this is a reasonable usecase, I think. Although with asynchrous messaging you would *usually* be in a different session when the copy was returned..... (not sure of the details of your app).

What are the requirements for the copy to be correctly persisted into the
database?  Just the ID to be the same?

Not even that. You can provide any id. So you can copy one object to another. Of course, if things are saveOrUpdateCopied by cascade, yeah, the id properties would always be used.


Would it be more efficient to not retrieve the original object from the
database?  I.E. if this object is a copy just put it in the cache instead of
the original, and also call update on the database.  This would save the
retrieval of the database version of the object.

Well, you could make this optimization but I am trying to draw a very clear distinction b/w saveOrUpdate() and saveOrUpdateCopy(), namely that saveOrUpdateCopy() is really saveOrUpdateForDummies(), ie. this will ALWAYS work, Hibernate figures out exactly what you really want, UNLESS you want efficiency - then use saveOrUpdate() and provide a _bit_ more yourself (like unsaved-value mapping, correct cascade mappings so we don't update too many rows, etc).


What happens in the current implementation if the copy object is not fully filled out, but the database version is? For example, lets say I have a parent object and a child object. The database version of both objects are fully filled with data. My "copy" parent does not have the relationship to the child object because I never sent that as part of the web service call, and I let the web service contruct the "copy" parent. If I call saveOrUpdateCopy with the parent object as it is, and then immediately retrieve that object back from the db with Hibernate will the retrieved object have the child or not?

Hibernate will remove the association. But why would you not just serialize a proxy, instead of nulling it before serializing?


Also, if my parent object has some fields filled in, and other fields are null, but the database version has all fields filled in, what will be in the database after the storeOrUpdateCopy call? Will the "copy" be there, and some fields null? Or will the original version be there, with the data from the copy overriding the fields it had data for?

The fields would be null.


--
Gavin King
JBoss Group
+61 410534454
http://hibernate.org



-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to