I want to generate UUID in spring controller. I am new to this and I was exploring following
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String corrId;
I do not want to associate this uuid with any database column/field but want it to be unique(I am not sure if this is possible)
When I try to print value of String 'corrId', it always gives me null
I have also tried but value of corrId is still null
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String corrId;
Am I doing something wrong here or my approach is completely wrong.
Thanks in advance!
You can simply define field this way:
@Transient
private UUID corrId = UUID.randomUUID();
Please read this post about UUID.randomUUID() and this one about @Transient.
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