为什么Hibernate将BIGINT映射到BigInteger [英] Why does Hibernate map BIGINT to BigInteger
问题描述
您可以在Dialect.java中看到它们的默认映射。我甚至发现了一个hibernate问题,但没有评论说明为什么会这样。
https://hibernate.atlassian.net/browse/HHH-7318
我假设必须有这种选择的原因,但我没有与谷歌任何成功。
另外,子类化我的数据库方言和覆盖这个影响会是什么?
谢谢!
很可能是因为 BIGINT
s可以是未签名的(至少在MySQL中,如果不在其他RDBMS中)。
唯一可以容纳64位无符号整数范围的Java类型是的BigInteger
。因为这会将18446744073709551615(2 64 - 1)转换为-1,所以对此使用 long
是不正确的。
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!
Quite probably because BIGINT
s 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.
这篇关于为什么Hibernate将BIGINT映射到BigInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!