我可以在 hibernate hbm 中使用 BigDecimal 作为 id 类型吗?
我正在使用休眠。它有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 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.