When uuid generated?

Hi,

@Id
@GenericGenerator(name = "jpa-uuid", strategy = "uuid2")
@GeneratedValue(generator = "jpa-uuid")
@Column(name = "id", nullable = false, length = 40)
private String id;

How generator work, I want get id before save, can I do this.

When you use the automatic UUID generators, the id is generated at flush time, not when you call persist or save.

If you want to get the id before flush, you can easily generated like this:

private String id = UUID.randomuuid();
1 Like