Hi all,
I'm using hibernate 2.1.6. I use it with PosgreSQL with the version 7.4.1.jdbc3 of the jdbc driver.
I'm asking myself about the right method to use to save a new instance of an object already existing in the database.
For instance :
(myObject has got an id and a name property, and the necessary getters and setters, the id is a generated="sequence" one.).
Session s = ...;
s.save(myObject);
Here, I commit.
Then, I get the object and try to save it as a new one. (i.e. as a new line in the db). The only way I've found to do it is to modify the id, setting it at 0 and calling saveOrUpdateCopy().
Is this the normal way or is there a better way to do it ?
In fact, I'd like to be able to do it because I'm versioning my objects.
I just want to save a new line with sometime only one field modified of the quieried instance. But if I use hibernate with the common save, it only calls update, which I absolutely don't want.
Could you help me ?
thanks a lot.
|