Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UuidGenerator Bean Type Mismatch?

Because strategy and UUIDGenerator is deprecated, this is the new UUID Generator:

@GenericGenerator(
            name = "UUID", 
            type = org.hibernate.id.uuid.UuidGenerator.class
    )

When using this, I get the following error:

Parameter 0 of constructor in org.hibernate.id.uuid.UuidGenerator required a bean of type 'org.hibernate.annotations.UuidGenerator' that could not be found

I wasn't able to find anything corresponding to this in the documentation.

For full disclosure, this is the whole annotation block used:

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "UUID")
@GenericGenerator(name = "UUID", type = org.hibernate.id.uuid.UuidGenerator.class)
@Column(...)
like image 652
J. M. Arnold Avatar asked Feb 24 '26 15:02

J. M. Arnold


1 Answers

I really suggest you to use @UuidGenerator instead of

@GeneratedValue(strategy = GenerationType.AUTO, generator = "UUID")
@GenericGenerator(name = "UUID", type = org.hibernate.id.uuid.UuidGenerator.class)

Something like this:

  @Id
  @UuidGenerator
  private UUID id; // or String

Because if you are going to check java docs of the annotation you will see that @UuidGenerator use @IdGeneratorType( org.hibernate.id.uuid.UuidGenerator.class ) that you need.

About the problem i really dont know where can be the problem but the solution that i suggest will help you to do this replacement also when specifying @UuidGenerator, we can choose the concrete version of UUID to generate.

And also some motivation to use it is described into 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

like image 186
Andrei Lisa Avatar answered Feb 27 '26 04:02

Andrei Lisa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!