Solved

number fields in Hibernate ?

Posted on 2004-08-20
7
779 Views
Last Modified: 2013-11-24
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


0
Comment
Question by:rdy1437
7 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11850666
>  when a table field declared as number and its nullable

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?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 11850667
It should probably map to Integer, not int. Try that
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11850672
i.e.

classs Equipment {
   Integer highTemp = null;

.........
}    
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 20

Expert Comment

by:Venabili
ID: 11852235
I agree with CEHJ on this. If you need a nullable Integer, you need the class Integer and not the primitive type int.

Venabili
0
 

Author Comment

by:rdy1437
ID: 11857703
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



0
 
LVL 35

Expert Comment

by:girionis
ID: 11867911
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>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11868544
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now