English 中文(简体)
我如何在Hibernate绘制大比宣言,以便我回到我提出的同样规模?
原标题:How do I map a BigDecimal in Hibernate so I get back the same scale I put in?

In Java, new BigDecimal("1.0") != new BigDecimal("1.00") i.e., scale matters.

然而,Hibernate/SQL服务器的情况显然并非如此。 如果我将比额表确定为一种特殊价值,通过Hibernate将BigDecimal从数据库中删除,然后重新插入我的物体,那么我又回到了大比Decimal,其规模不同。

例如,1.00美元的价值回落到1 000美元,因此我假定,我们把BigDecimals重新绘制成一个名为NUMERIC(19,6)的栏目。 我只能把该栏界定为必要的比额表,因为我需要在同一个栏中储存美元和Yen值(例如)。 我们需要在数据库中代表比埃拉姆赛语作为数字类型,以便利用外部报告工具。

是否存在一种“适当”绘制大比埃拉尔地图的“自由用户”或我是否必须写自己?

问题回答

Just for informational sake, I can tell you that the creation of the BigDecimal coming back from the database is done by the proprietary JDBC driver s implementation of the getBigDecimal method of the database-specific ResultSet sub-class.

我发现,这样做是因为有人夸大了Hibernate source代码,试图找到对我自己的答案:question

我认为,这项工作将会奏效,但我确实如此。

public class BigDecimalPOJO implements Serializable {

    private static final long serialVersionUID = 8172432157992700183L;

    private final int SCALE = 20;
    private final RoundingMode ROUNDING_MODE = RoundingMode.CEILING;
    private BigDecimal number;

    public BigDecimalPOJO() {

    }

    public BigDecimal getNumber() {
        return number.setScale(SCALE, ROUNDING_MODE);
    }

    public void setNumber(BigDecimal number) {
        this.number = number.setScale(SCALE, ROUNDING_MODE);
    }
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签