2

I am using "double" in Hibernate .hbm.xml files, and when I generate classes with Hibernate Tool I get class property which has primitive type double. I want this property to be java wrapper type Double. How can I achieve this? If I change this manually in my classes, is it going to give any issues to hibernate?

Thanks

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
azec-pdx
  • 4,790
  • 6
  • 56
  • 87
  • Are you sure you want "double" and not "BigDecimal"? For monetary values, "double" is problematic because of rounding (3.11 - 3.1 is not 0.01 using double). – Thomas Mueller Sep 15 '10 at 15:05

3 Answers3

1

I am using "double" in Hibernate .hbm.xml files, and when I generate classes with Hibernate Tool I get class property which has primitive type double. I want this property to be java wrapper type Double. How can I achieve this?

Is the property nullable in the hbm.xml mapping? If it is, you should get a Double.

If you can't change the mapping, you could override the default behavior:

  • override the column specifically in reveng.xml
  • use a type-mapping and not-null set to false to handle it for all columns
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
0

If you can add below statement under type-mapping in your hibernate.reveng.xml ,then you pojos will be generated with double type as java.lang.Double.

<sql-type jdbc-type="DOUBLE"  not-null="false" hibernate-type="double" /> 

Or

if you can add not-null="false" in your hbm files,that also address your issue.

<property name="salary" type="double">
            <column name="SALARY"  not-null="false" />
        </property>
Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38
0

It only issue you could have is if your property is null amd the column is declared as not null. So I would advise you to always initialize it.

Maurice Perry
  • 32,610
  • 9
  • 70
  • 97