我可以在 hibernate hbm 中使用 BigDecimal 作为 id 类型吗?

发布于 2024-12-17 18:57:43 字数 396 浏览 5 评论 0原文

我正在使用休眠。它有 id 列,精度为 20,如下所示,但为 NUMBER 类型。

NUMBER(38,20) - 这是为表(Oracle 数据库)的 id 列指定的大小。

id 由我们的应用程序生成。在实体中,如果我使用 Float 或 Double,它无法容纳 20 个精度。但 java.math.BigDecimal 可以容纳这么多精度。 但问题是我可以在 hbm 中使用 BigDecimal 吗?会有什么问题吗?有时我可能无法准确发送 ID。那时休眠会生成任何空精度并插入吗?

<id name="someId" column="SOME_ID" type="java.math.BigDecimal"/>

请建议!

i am using hibernate. it has id column with 20 precisions as below but of NUMBER type.

NUMBER(38,20) - this is the size given to id column of the table(Oracle database).

This id is generated by our application. in entity if i use Float or Double it cannot accommodate 20 precisions. but java.math.BigDecimal can accommodate these many precisions.
but the problem is can i use BigDecimal in hbm as below? will there be any problems? some times i may not send id with precisions. that time will hibernate generates any empty precision and inserts?

<id name="someId" column="SOME_ID" type="java.math.BigDecimal"/>

Please suggest!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲琵琶半遮面シ 2024-12-24 18:57:43

您可以使用 type="big_decimal"。在任何情况下,您都不应尝试使用 Float 或 Double 来实现此目的。

You can use type="big_decimal". Under no circumstances should you even attempt to use Float or Double for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文