简体   繁体   中英

Hibernate type used to map java.lang.Double

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

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM