| When trying to retrofit an existing entity with @Version for optimistic locking I discovered that null values for the version column would always fail to update with an OptimisticLockException. Turning on debug I found the reason to be that the SQL that Hibernate was generating was something like this:
This clause will never match anything (in oracle at least) so was failing. It should be doing
WHERE version_column is null
For cases where the existing value is null. I was able to work around the issue by manually inserting a value into the column for existing rows, but this bug created a lot of confusion and caused a lot of time to be spent debugging the issue. I think Hibernate should handle this case a little better. |