Null optlock causes updates to fail
Wednesday, January 6th, 2010 04:58 pmI've spent the afternoon tracing a legacy data issue, which was preventing any changes on older records from being saved. It turns out that having a null value for an optlock in the database, causes a org.hibernate.StaleObjectStateException; I also saw javax.persistence.EntityNotFoundException in the logs.
Funny, this is the reverse of what most other people have run into -- most other people getting the EntityNotFoundException were doing so because they had an invalid id, and the fix for them was to make their id NULL.
In hindsight, it was to be expected. Would it be better behavior to instead handle this case more gracefully (treat null as a 0, instead of an exception)? I can't make up my mind. It would have made things easier for me, but it does seem rather an edge case, made possible only because we'd migrated old data into the system.
Funny, this is the reverse of what most other people have run into -- most other people getting the EntityNotFoundException were doing so because they had an invalid id, and the fix for them was to make their id NULL.
In hindsight, it was to be expected. Would it be better behavior to instead handle this case more gracefully (treat null as a 0, instead of an exception)? I can't make up my mind. It would have made things easier for me, but it does seem rather an edge case, made possible only because we'd migrated old data into the system.