db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Derby with beans and null primitives
Date Wed, 30 Nov 2005 17:34:21 GMT

I think your issue is that you are using the wrong representation for  
the data.

If you have nullable columns, map them to Integer.

If you have non-nullable columns, map them to int.

Otherwise, you will have this issue. If you are stuck with an  
inflexible object model and an inflexible database schema, then you  
have to have a policy in place for handling the mismatch. That is,  
how to store a null Integer into a non-nullable column, and how to  
store a null column value into an int. Your choices typically are to  
throw an exception or to represent null as zero. If you choose to  
represent null as zero you lose information. But this is an  
application policy choice.


On Nov 29, 2005, at 9:28 PM, Michael McCutcheon wrote:

> I'm implementing a utility class that populates 'beans' with data  
> from tables in derby.  Suppose I have the following 'bean':
> public class Person
> {
>  private String firstName;
>  private String lastName;
>  private int weight;
>  public void setWeight(int inWeight)
>  {
>    this.weight = inWeight;
>  }
>  public int getWeight()
>  {
>    return this.weight;
>  }
> }
> I select out of a Person table to get the information to populate  
> this bean.
> But what happens if weight is nullable in the table?
> Since you can't put nulls into primitives in Java, how is this  
> handled?
> This is a real problem because 0 is definately different than no  
> value.
> Also is there some standard for how JSP's deal with beans with  
> primitive types?
> How should null primitives be handled in beans like this?
> Thanks
> Mike

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!

View raw message