Search code examples
javamavenliquibaseliquibase-hibernateliquibase-sql

liquibase maven plugin UUID vs BINARY(255)


  • I use the liquibase-maven-plugin to generate the database migration scripts.
  • But liquibase generates the UUID id fields as BINARY(255).
  • This in itself is not a problem as the IDs for new entities are generated by hibernate. So database support for uuid is not required.
  • but my problem now are the sample data in csv files, in which I have to insert the uuid as binary.

So I see 2 possible solutions for my problem:

  1. let liquibase-maven-plugin generate the UUID fields as real UUID database fields.
  2. tell liquibase to transform the uuid in my csv files into binary before inserting.

Does anyone know how to perform either 1. or 2. ?

Or is there even a 3. option I am not aware of ?

java entity

@Entity
public class TestEntity {
  @Id
  @GeneratedValue
  private UUID id;
  @Column
  private String name;
}

change set generated by liquibase-maven-plugin

- changeSet:
    id: 1638440755794-7
    changes:
    - createTable:
        columns:
        - column:
            constraints:
              nullable: false
              primaryKey: true
            name: id
            type: BINARY(255)
        - column:
            name: name
            type: VARCHAR(255)
        tableName: test_entity

sample-data.csv - NOT WORKING

id,name
0da87def-2d39-47f1-ae4a-310fc37a8aa0,meinName

sample-data.csv - WORKING

id,name
Dah97y05R/GuSjEPw3qKoA==,meinName

Solution

  • Faced the same problem when using PostgreSQL. I decided by specifying an explicit dialect in the liquibase-maven-plugin settings.

    <referenceUrl>hibernate:spring:ru.mts.iot.core.metainvsrv.entity?dialect=org.hibernate.dialect.PostgreSQL95Dialect</referenceUrl>