I have a database column whose type is “NUMBER” in oracle.
I want to map it by long or Long. But I’m not sure which type I should use, the primitive type or the Object type? Is there a convention? My case is that the value is the only thing I want from DAO method:
public class SampleDAO{
public long fetchNumberValue(){
//Is it better to return long value instead of Long?
}
}
And what if I want to wrap that value in an object?
public class SampleObject(){
//Is it better to use Long to use methods like hashCode() inherited from Object?
private Long value;
}
EDIT:
Thanks all for the answers. I got it that it depends on whether I need accept null value.
This database column is not nullable, actually it’s the primary key. And it may have such values like 0, 1, 2 etc… OK, another question appears, how can I know if I get a matched row with a 0 value or no matched row? java.sql.ResultSet.getLong returns a long value and if the column’s value is SQL NULL then 0 is returned. Or is it a bad practice to have a 0 valid in such a column?
Longwill permit anullvalue, where aslongmust not be null. So I would match it do your database column – is it nullable or not?Edit to the edited question:
To check if a value was actually
0ornullin the database, useResultSet.wasNull.