Hibernate version:3
I have a property called Count . I want to save anything that i get from the customer. So we are saving the properties in the database by having 2 fields called original Count and Count.
Original Count contains the data that the customer sent in the form of a string.
Count contains the data converted into integer format.
Mapping documents:
<property name="Cnt" type="int" column="CNT"/>
<property name="OrigCnt" type="String" column="ORIG_CNT"/>
java source . setters and getters:
Code:
int cnt;
String origCnt;
public int getCnt() {
return Cnt;
}
public void setCnt(int Cnt) {
this.Cnt = Cnt;
}
public String getOrigCnt() {
return origCnt;
}
public void setOrigCnt(String origCnt) {
this.origCnt = origCnt;
try{
setCnt(Integer.parseInt(origCnt));
} catch (NumberFormatException nfe){
}
}
By doing this the Cnt field is always set as 0. i want to set it as null in the database since its a nullable field.
I know that if i change the cnt data type to Integer it will solve my problem but that will have an effect in n number of places in the existing code. Can we do something in the hibernate mapping?
I have the same scenario for amount field. i am using BigDecimal as the datatype for the amount so everything should work.
Any suggestions?
Thanks in advance