What I am trying to achieve is generate a UUID which is automatically assigned during a DB Insert. Similar to the primary key column named "id" generating an id value.
The model values looks something like this:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
private Long id;
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "uuid", columnDefinition = "BINARY(16)")
private UUID uuid;
But when the DB insert is done. the "uuid" is empty.
Help is greatly appreciated. And if I am asking an obvious stupid question I am sorry.
Hibernate supports 2 of them: The default strategy generates the UUID based on random numbers (IETF RFC 4122 Version 4). You can also configure a generator that uses the IP address of the machine and a timestamp (IETF RFC 4122 Version 1).
Version-1 UUIDs are generated from a time and a node ID (usually the MAC address); version-2 UUIDs are generated from an identifier (usually a group or user ID), time, and a node ID; versions 3 and 5 produce deterministic UUIDs generated by hashing a namespace identifier and name; and version-4 UUIDs are generated ...
Can you try?
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", columnDefinition = "VARCHAR(255)")
private UUID id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With