I am wondering if someone can help her.
I am using JPA to entity manager to send data from xml into a database. One of the fields in the database is set as a double. This field is nullable.
When loading the data into the database. The parsers loads in the last non null value for all null value fields. Is their a way I can set a null value for the field and if the field is empty - to load the default value.
Currently I tried setting the value in the JPA getter and setter class but it did not help
//putting in 0.0 here to help with null values issues for float element
@Column(columnDefinition="double precision default '0.0'",name="field")
//the 0.0 is not working here, so going to try it in the column definition
private double field=0.0;
Thanks in advance
NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
This topic has been locked.
1 reply Latest Post - 2012-08-14T15:06:35Z by leealber
Pinned topic JPA - send a null or 0.0 value to double field
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2012-08-14T15:06:35Z at 2012-08-14T15:06:35Z by leealber
leealber 1100005V7019 PostsACCEPTED ANSWER
Re: JPA - send a null or 0.0 value to double field2012-08-14T15:06:35Z in response to SystemAdminThe attribute "field" of type double is a primitive type. From Java perspective, it will always has a value and default to 0.0. So JPA will always store 0.0 to the database even if it is not set.
You may want to define "field" as Double type, which you can have null value set in the database.
The tricky part is to set the value to 0.0 on load if the database column is null. You may be able to simulate it in the getField() methods and return 0.0 if "field" is null.
Hope this help.