Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate UUID.hex vs UUID2

I'm using hiberate 4.3.5 Final and encounter following warning

org.hibernate.id.UUIDHexGenerator WARN - HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead

So i have change my mapping file unique id generator from

generator class="uuid.hex"

to

generator class="uuid2"

Coding wise i know this is just a warning but is there any other advantage using uuid2 over uuid.hex. Is it more effective way or standard way to use uuid2 or best coding practise? I'm trying to go for best coding practise in my application. Any guru's can help me on this?

One additional thing i notice is that uuid2 key is having "-" compare to the uuid.hex. Any disadvantage?

like image 899
viknesh Avatar asked Oct 16 '25 01:10

viknesh


1 Answers

The missing "-" is the exact difference.

As the documentation of UUIDHexGenerator says:

A UUIDGenerator that returns a string of length 32, This string will consist of only hex digits

And also:

Users can also configure it to use a separator (config parameter "separator") which separates the hexidecimal digits into 8{sep}8{sep}4{sep}8{sep}4. Note specifically that this is different than the IETF RFC 4122 representation of 8-4-4-4-12.

However, a UUID must have these "-" at certain positions to be valid.

like image 82
Jimmy T. Avatar answered Oct 17 '25 13:10

Jimmy T.



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!