dear all,
I have a question please help me.
suppose I have file mapping SysConfig.hbm.xml like :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="appserver.domain.SysConfig" table="SYSCONFIG">
<id column="PARAMID" name="id" type="string">
<generator class="assigned"/>
</id>
<property column="PARAMVALUE" length="7" name="parameterValue" type="integer"/>
</class>
</hibernate-mapping>
-------- and I have file mapping SysConfig.java like ;
public class SysConfig implements Serializable {
/** identifier field */
private String id;
/** nullable persistent field */
private int parameterValue;
/** full constructor */
public SysConfig(java.lang.String id, int parameterValue) {
this.id = id;
this.parameterValue = parameterValue;
}
/** default constructor */
public SysConfig() {
}
/** minimal constructor */
public SysConfig(java.lang.String id) {
this.id = id;
}
/--------- Getters and Setters are deleted ---------------/
}
As you can see the "parameterValue" are map to java primitive (int) rather than Object Integer. The problem arose when I use :
hs.find("SELECT s FROM SysConfig s");
and the database table are like this
Table SYSCONFIG
---------------------------------------------------------------------
PARAMID | PARAMVALUE
--------------------------------------------------------------------
1 | <NULL>
I think the problem exist because Hibernate "cannot" persist variable "parameterValue" (primitive int) to be Null.
because doing
setParameterValue(Null)
would throws exception because the expected input value is (primitive) int not Object Integer.
What I like to ask you all is how can I make the Null value become 0 before Hibernate set the Null value into "parameterValue"? Or can you would propose any other solution?
The constraint are :
1. I am forbiden to change any database settings at all.
2. I do not want to change primitive value int to be Object Integer.
The preferable change to correct the problem :
1. Through Hibernate Settings.
2. Any
Please give me step-to-step instruction to correct my problem?
thank you very much for your time and consideration.
|