rdy1437
asked on
number fields in Hibernate ?
Hi guys! I'm developing a web applications using hibernate1.8 and struts1.0. Well I can't use the new versions of these tools because the company I work used the jdk1.3. :-( . The problem is that, in hibernate, when a table field declared as number and its nullable and when i query this in hibernate I'm getting a nullpointerexception (null can't be assinged to an int type).
classs Equipment {
int highTemp = 0;
.........
}
and the Table Equipment hightemp is a number and it's a nullable.
Any work around on this?Or maybe it's a bug in this version of hibernate, maybe just change the type of my table field
thanks in advance!
raymond
classs Equipment {
int highTemp = 0;
.........
}
and the Table Equipment hightemp is a number and it's a nullable.
Any work around on this?Or maybe it's a bug in this version of hibernate, maybe just change the type of my table field
thanks in advance!
raymond
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i.e.
classs Equipment {
Integer highTemp = null;
.........
}
classs Equipment {
Integer highTemp = null;
.........
}
I agree with CEHJ on this. If you need a nullable Integer, you need the class Integer and not the primitive type int.
Venabili
Venabili
ASKER
Hi girionis! here's the database schema
EquipmentTypes
code varchar(20) not null
description varchar(20) not null
hightemp number
....
so when you enter values(using sql plus) the field hightemp will just be blank.My program query this table only for displaying, the maintenance of this is done by others.And my hibernate mapping is like this (i ommited some of the tags)
<property name="code"/>
<property name="desc" column="description"/>
<property name="hightemp"/>
raymond
EquipmentTypes
code varchar(20) not null
description varchar(20) not null
hightemp number
....
so when you enter values(using sql plus) the field hightemp will just be blank.My program query this table only for displaying, the maintenance of this is done by others.And my hibernate mapping is like this (i ommited some of the tags)
<property name="code"/>
<property name="desc" column="description"/>
<property name="hightemp"/>
raymond
Are you using MS Access? A "number" maps to an object type in Java, so CEHJ was right, change the hightemp to an Integer. Otherwise change the type of the column in the db. And as a side note, it's always good to do proper mapping in the config files:
<property name="hightemp">
<column name="hightemp" sql-type="number"/>
</property>
<property name="hightemp">
<column name="hightemp" sql-type="number"/>
</property>
:-)
It shouldn't be, it should be 0 not null. Can you post the hibernate mapping (just the specific tag that specifies this field) and the db schema for this field?