postgresql - Hibernate 在尝试使用生成的 UUID 持久化 DTO 时不断询问 hibernate_sequence
问题描述
我正在使用 dropwizard-hibernate 和 postgres(休眠版本 5.3.7)
对于我的 DTO,我有一个包含 ID 字段的基本 DTO(所有 DTOS 都扩展了此类)
在数据库模式中,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(根据最新的休眠文档,对于UUID配置应该足够了)和许多其他注释组合但每次我尝试持久化实体我得到了缺少序列的问题。
我知道我可以“修复它”只需在数据库中添加 hibernate_sequence 表,但我根本不需要它。
解决方案
我已经使用了它,它按预期工作:
@Column(name = "uid")
@Generated(GenerationTime.ALWAYS)
@Type(type = "pg-uuid")
private UUID uid;
我意识到这@Generated
是一个遗留注释,但它似乎有效。
推荐阅读
- javascript - Javascript XMLHttpRequest - 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头
- javascript - 更改值时无法提交隐藏的输入
- mongodb - 重置 Meteor 后如何停止清理 mongo db [Meteor]
- c# - 仅检查剃须刀页面中可见表单属性的 ModelState OnPost
- c# - 如何使用 C# 从名称中删除首字母
- c# - IlGenerator 发射
- javascript - 使用 Bootstrap 启动时出现多个错误
- c# - 在 Form2 中访问 SelectedPath
- linux - webench源码中gethostbyname使用问题
- sql - oracle sql 一列有2列