根据文档,不推荐使用以下用法:
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
type()
!但是我如何才能将上面的语句转换为对 type()
执行相同的操作呢?仅提供 hibernate UUIDGenerator 是行不通的。
正如上面两条评论所暗示的那样,
type
现在属于类型类。因此修复很简单:
@GenericGenerator(
name = "UUID",
type = org.hibernate.id.uuid.UuidGenerator.class
)
使用新的注释@UuidGenerator
旧解决方案:
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
private UUID id;
新解决方案(自 hibernate 6.2 起):
@Id
@UuidGenerator
private UUID id;
@Id
@UuidGenerator(style = UuidGenerator.Style.TIME)
private UUID id;