Liquibase: change INT auto-increment column to BIGINT using modifyDataType refactoring with H2 database

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
+5
2

(Hibernate 3.6.2.Final, H2 1.3.160, : org.hibernate.dialect.H2Dialect), :

  • GenerationType AUTO, - INT, type - SEQUENCE.
  • GenerationType AUTO, - BIGINT, - IDENTITY. , id- ID BIGINT PRIMARY KEY, ID BIGINT IDENTITY ( PRIMARY KEY H2 ).

:

, SEQUENCE, ,

@GeneratedValue(strategy = GenerationType.SEQUENCE)

, . , , documentation BIGINT . , , ,

- IDENTITY startValue (- ) GenerationType.AUTO, .

+6

@GenerationType (, IDENTITY), Hibernate, . .

, .

H2 Liquibase , ; H2 Liquibase . , ?

EclipseLink , 0 (!), null , , , Hibernate .

, , , , .

+1

All Articles