- 我使用liquibase-maven插件生成数据库迁移脚本
- 但是liquibase生成UUID id字段作为BINARY(255(
- 这本身不是问题,因为新实体的ID是由hibernate生成的。因此,不需要对uuid的数据库支持
- 但我现在的问题是csv文件中的示例数据,我必须在其中以二进制形式插入uuid
所以我看到了我的问题的两种可能的解决方案:
- 让liquibase-maven插件将UUID字段生成为真实的UUID数据库字段
- 告诉liquibase在插入之前将csv文件中的uuid转换为二进制文件
有人知道如何执行任一操作吗。或者2
或者甚至有3。我不知道的选项
java实体
@Entity
public class TestEntity {
@Id
@GeneratedValue
private UUID id;
@Column
private String name;
}
liquibase-maven插件生成的更改集
- 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-不工作
id,name
0da87def-2d39-47f1-ae4a-310fc37a8aa0,meinName
sample-data.csv-工作
id,name
Dah97y05R/GuSjEPw3qKoA==,meinName
在使用PostgreSQL时也面临同样的问题。我决定在liquibase-maven插件设置中指定一个明确的方言。
<referenceUrl>hibernate:spring:ru.mts.iot.core.metainvsrv.entity?dialect=org.hibernate.dialect.PostgreSQL95Dialect</referenceUrl>
从3.6版本起,Liquibase似乎支持UUID:
https://docs.liquibase.com/workflows/liquibase-community/working-with-uuids.html