因为strategy
和 UUIDGenerator
已弃用,这是新的 UUID 生成器:
@GenericGenerator(
name = "UUID",
type = org.hibernate.id.uuid.UuidGenerator.class
)
使用此方法时,出现以下错误:
Parameter 0 of constructor in org.hibernate.id.uuid.UuidGenerator required a bean of type 'org.hibernate.annotations.UuidGenerator' that could not be found
我在documentation中找不到与此相对应的任何内容。 .
为了充分披露,这是使用的整个注释 block :
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "UUID")
@GenericGenerator(name = "UUID", type = org.hibernate.id.uuid.UuidGenerator.class)
@Column(...)
最佳答案
我真的建议你使用@UuidGenerator
而不是
@GeneratedValue(strategy = GenerationType.AUTO, generator = "UUID")
@GenericGenerator(name = "UUID", type = org.hibernate.id.uuid.UuidGenerator.class)
类似这样的事情:
@Id
@UuidGenerator
private UUID id; // or String
因为如果您要检查注释的 java docs
,您将看到 @UuidGenerator
使用
@IdGeneratorType( org.hibernate.id.uuid.UuidGenerator.class )
您需要的。
关于这个问题,我真的不知道问题出在哪里,但是我建议的解决方案将帮助您在指定@UuidGenerator
时进行此替换,我们可以选择UUID的具体版本生成。
8.5. User-defined generators 中描述了使用它的一些动机。
These APIs are new in Hibernate 6, and supersede the classic IdentifierGenerator interface and @GenericGenerator annotation from older versions of Hibernate.
@UuidGenerator A more flexible generator for RFC 4122 UUIDs
关于java - UuidGenerator Bean 类型不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77128492/