为什么Hibernate将BIGINT映射到BigInteger [英] Why does Hibernate map BIGINT to BigInteger

查看:768
本文介绍了为什么Hibernate将BIGINT映射到BigInteger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数数据库中,BIGINT是一个64位整数。有谁知道为什么Hibernate将这些映射到BigInteger而不是Long?我可以处理这些,但我只是好奇。



您可以在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 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.

这篇关于为什么Hibernate将BIGINT映射到BigInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆