Lorenzo created Bug HHH-8314
Issue Type: Bug Bug
Affects Versions: 4.2.2
Assignee: Unassigned
Attachments: HBM1.PNG, HBM2.PNG, HBM3.PNG, HBM4.PNG, HBM5.PNG, HBM6.PNG, HBM7.PNG
Created: 16/Jun/13 10:42 AM
Description:

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????

Environment: WIndows 7
Hibernate 4.2.2
Project: Hibernate ORM
Labels: hibernate
Priority: Major Major
Reporter: Lorenzo
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira