Hi everybody,
I've been struggling with the same problems for a few days now and still can't find a solid solution. I just upgraded to Hibernate 3.1.3 from 2.1 and when going though the code realized that session.save(Object, Serializable) is deprecated now. I am in a pretty complicated situation now, as I relied on this method for restoring key persistent objects. For these objects I must preserve Hibernate IDs, as they are used to generate URLs through which these objects are referenced externally and the requirement is to keep these ids. Normally all news objects are saved with regular session.save calls, however it's only at backup and restore phases when the ids of some objects must be dealt with very carefully (i.e. preserved).
These two posts seem to address the same issue:
http://forum.hibernate.org/viewtopic.php?t=951515
http://forum.hibernate.org/viewtopic.php?t=959631
I tried to replace the call to session.save(Object, Serializable) with call to session.replicate(Object) where the parameter passed to the call has the id set, but it introduced 2 problems:
1) Ids didn't get preserved, but rather were replaced by newly generated ones
2) For certain objects "org.hibernate.TransientObjectException: instance with null id passed to replicate()" started to show up, which wasn't there when I used session.save(Object, Serializable)
(1) is a very strange observation, as JavaDocs for replicate say that it should reuse the current id value. (2) is something to expect, as I guess the whole network of the objects that get saved must have their ids set in order to be "savable". To fix that I manually persisted parts of the network first, and only then saved the larger object.
Altogether, there is nothing that stops me from using the classic session, where the save method that I am interested in is present. It's just I don't have the right feeling about having to use deprecated method for such basic operation as saving object with a certain id.
Is there a workaround to use the functionality from session.save(Object, Serializable) w.o. having to use deprecated methods?
Thank you very much for taking the time to read this post. I hope to see a reply here soon.
Sincerely,
Nick.
Hibernate version: 3.1.3
Name and version of the database you are using: MySQL 5.0