2
  • 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
aminator
  • 396
  • 7
  • 18

2 Answers2

1

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>
0

It looks like as of version 3.6 Liquibase supports UUIDs:

https://docs.liquibase.com/workflows/liquibase-community/working-with-uuids.html

Mor Blau
  • 420
  • 3
  • 15
  • thanks for your reply. I know that liquibase supports UUIDs. But the liquibase-maven-plugin generates the field as a binary(255) even though the entities id attribute is of type UUID. – aminator Dec 06 '21 at 09:50