Hi,
I make hibernate persist an object with the saveOrUpdate() method.
The object has some properties, but before hibernate persists it to the database, it's id is null.
Hibernate generates an id before persisting (as is specified in the mapping file), and saves the object to the database.
From this moment however, the id of the object in memory is still null.
So when I try call saveOrUpdate() again on the very same object (with id == null), hibernate thinks it's a brand new object because id is null and saves it again instead of updating it.
Now I ask myself which is the best way to handle an issue like this.
First saving the object, and then finding it back in the database doesn't seem like a good option to me (performance wise)?
Someone told me that saveOrUpdate() returns the id, which would be ideal, but I checked the JavaDoc and it returns void.
Gr,
nkr1pt
|