I have a Grails application that I am migrating from 1.0.3 to 1.3.7
It was my understanding that tables that used version numbers would start at zero and auto increment on row update. All of the legacy data that I have shows the version cells to be null for each row, but new rows that are entered have a version number of 0.
Did version 1.0.3 of Grails not support this concept? Should I update all of these rows for all appropriate tables to user 0 instead of null? What are the implications? Thanks.
Grails has always supported the version column to implement Hibernate’s optimistic locking. When you update an instance Hibernate generates SQL that compares the current and previous version, and will throw an exception if they differ. Since SQL
nullcan never equal anything, any attempt to update those rows will trigger an exception.The fix is simple though – just run a query to set null values to 0, something like
update table_name set version=0 where version is null.Once you’ve done this you should alter those columns to be not-null to avoid null values in the future.