1

I'm using binary format to store UUIDs in mysql database ( binnary(16) )

and I'm useing the following code in hibernate

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column( columnDefinition = "BINARY(16)", length = 16 )
private UUID id;

those generated values look different and seems as garbage values when I view in phpmyadmin

if I use UUID() function in mysql query it seems fine.
Then how to tell hibernate to use UUID() function

1 Answer 1

1

What is BINARY Type ?

They contain byte strings rather than character strings. This means that they have no character set, and sorting and comparison are based on the numeric values of the bytes in the values. That's why they look like garbage values

What does UUID() function create?

A UUID is designed as a number that is globally unique in space and time. Two calls to UUID() are expected to generate two different values, even if these calls are performed on two separate computers that are not connected to each other.A UUID is a 128-bit number represented by a utf8 string of five hexadecimal numbers in aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee format: That's why they are readable

UUID() function doesn't create a byte string, but a character string. so, they are very different .

Sign up to request clarification or add additional context in comments.

5 Comments

is there any way to tell hibernate to use UUID() function ?
Which version of Hibernate do you use?
Hibernate version 4.3.5
Check this link You will understand.
Above link is broken, use this one instead (archive.org).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.