Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Hibernate map BIGINT to BigInteger

In most databases a BIGINT is a 64bit integer. Does anyone know why Hibernate maps these to BigInteger instead of Long? I can handle these well but I'm just curious.

You can see their default mapping for this type in Dialect.java. I even found a hibernate issue but there are no comments indicating why this would be the case.

https://hibernate.atlassian.net/browse/HHH-7318

I assume there must be a reason for this choice but I haven't had any success with google.

Also, what would be the impact of subclassing my databases dialect and overriding this?

Thanks!

like image 545
robert_difalco Avatar asked Dec 11 '14 18:12

robert_difalco


1 Answers

Quite probably because BIGINTs can be unsigned (in MySQL at least, if not in other RDBMSs).

The only Java type that can hold the full range of a 64-bit unsigned integer is BigInteger. It would be incorrect to use a long for this, as this would convert 18446744073709551615 (264 - 1) to -1.

like image 191
Luke Woodward Avatar answered Sep 23 '22 21:09

Luke Woodward