Hibernate 在尝试使用生成的 UUID 保留 DTO 时不断询问 hibernate_sequence
Hibernate keeps asking for hibernate_sequence when trying to persist DTO with generated UUID
我正在使用 dropwizard-hibernate 和 postgres(休眠版本 5.3.7)
对于我的 DTO,我有一个包含 ID 字段的基本 DTO(所有 DTOS 都扩展了这个 class)
在数据库架构中,Id 如下所示
id uuid default gen_random_uuid() not null
我的ID配置是这样的:
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid2")
private UUID id;
理论上这应该可行,但每次我尝试保留一个实体时,我都会收到一条错误消息
ERROR: relation \"hibernate_sequence\" does not exist\
我已经尝试了一切,但没有任何效果..我尝试了@Id和@GeneratedValue(根据最新的hibernate文档,对于UUID配置应该足够了)和许多其他注释组合,但每次我尝试坚持实体我得到丢失的序列问题。
我知道我可以 "fix it" 只需在数据库中添加 hibernate_sequence table 但我根本不需要它。
我已经使用过它并且它按预期工作:
@Column(name = "uid")
@Generated(GenerationTime.ALWAYS)
@Type(type = "pg-uuid")
private UUID uid;
我意识到 @Generated
是遗留注释,但它似乎有效。
我正在使用 dropwizard-hibernate 和 postgres(休眠版本 5.3.7)
对于我的 DTO,我有一个包含 ID 字段的基本 DTO(所有 DTOS 都扩展了这个 class)
在数据库架构中,Id 如下所示
id uuid default gen_random_uuid() not null
我的ID配置是这样的:
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid2")
private UUID id;
理论上这应该可行,但每次我尝试保留一个实体时,我都会收到一条错误消息
ERROR: relation \"hibernate_sequence\" does not exist\
我已经尝试了一切,但没有任何效果..我尝试了@Id和@GeneratedValue(根据最新的hibernate文档,对于UUID配置应该足够了)和许多其他注释组合,但每次我尝试坚持实体我得到丢失的序列问题。
我知道我可以 "fix it" 只需在数据库中添加 hibernate_sequence table 但我根本不需要它。
我已经使用过它并且它按预期工作:
@Column(name = "uid")
@Generated(GenerationTime.ALWAYS)
@Type(type = "pg-uuid")
private UUID uid;
我意识到 @Generated
是遗留注释,但它似乎有效。