|
I am developing a web app that is using REST web services.
To store a new object, I need to be able to create the proper REST URL as follows:
PUT /rest/hotels/1000 where 1000 is the ID of a new HOTEL.
This new ID is fetched using a sequence.
In the code, I issue a saveOrUpdate on that object. It fails. In the log I see it is NOT trying to INSERT the object but rather UPDATE it. ANd because it does not yet exist, it says a Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1.
I downloaded the source code and debugged it and the BUG is in here:
Identifier.java line 139:
/**
- Does the given identifier belong to a new instance?
*/
public Boolean isUnsaved(Object id)
Unknown macro: { LOG.tracev( "ID unsaved-value}
Object id is a Long with value 1000.
value is NULL at the time.
isUnsaved thus returns false because id==null is false and since 1000 does not equal null, the method returns false saying isUnsaved = false thus assuming the object is saved!! Even if I put a get(1000) on the object I get back null meaning it indeed does not yet exist!!
So apparently, as soon a an object has an ID hibernate assumes it is unSaved????
|