I have a primary key column, which is an INT column, which I would like to change to BIGINT. Our test and production environment uses MySQL, but for unit tests we use the embedded H2 database.
I created the following Liquibase refactoring:
...
<changeSet id="1" author="trond">
<modifyDataType tableName="event" columnName="id" newDataType="BIGINT" />
<rollback>
<modifyDataType tableName="event" columnName="id" newDataType="INT" />
</rollback>
</changeSet>
...
Refactoring works, but when I try to save an object to the database using Hibernate, I get the following error message (I wrapped the error message):
ERROR org.hibernate.util.JDBCExceptionReporter [main]: NULL not allowed for column "ID";
SQL statement: insert into event (id, eventtime, guid, meta, objectguid, originatorid, subtype, type) values (null, ?, ?, ?, ?, ?, ?, '0') [90006-140]
JDBC exception on Hibernate data access:
SQLException for SQL [insert into event (id, eventtime, guid, meta, objectguid, originatorid, subtype, type) values (null, ?, ?, ?, ?, ?, ?, '0')];
SQL state [90006]; error code [90006]; could not insert: [event.MyEvent];
nested exception is org.hibernate.exception.GenericJDBCException: could not insert: [event.MyEvent]
The MyEvent class inherits from AbstractBaseEvent, which defined the following Hibernate mapping in code:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
A few points:
- Hibernate mapping works before data type refactoring
- Liquibase Version 2.0.1
- Regardless of whether this works with MySQL has not yet been tested