• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

CMP 2.0 Using primitive type for fields that have null values

My problem is I have a CMP 2.0 Bean and one of columns is of type int and I'm using int as the return type in getAccessAuthorizationId() instead of java.lang.Integer.  When I query a bean by Id and it gets to that column I get a java.lang.NullPointerException.

My question:  Is there an xdoclet tag that I can set to allow the query of a null value on a primitive and just let the container set the value to the primitives default.  I tried the following tag

/**
     * Getter for CMP Field companyName
     *
     *
     * @ejb.persistent-field
     * @ejb.interface-method   view-type="both"
     * @jboss.column-name name="access_authorization_id"
     * @jboss.persistence not-null="true" ///THIS didn't work, and since by default its false and that doesn't work either I don't think this is working.
     *
     */
    public abstract int getAccessAuthorizationId();
0
phoenixsilver
Asked:
phoenixsilver
  • 2
1 Solution
 
aozarovCommented:
I don't think so, what value do you expect when its Null ? 0, -1, ...
You will need to change it to Integer.
public abstract Integer getAccessAuthorizationId();
0
 
phoenixsilverAuthor Commented:
I wanted a zero, or at least some way of specifying a default value, cause I don't want to have to check for a null for all option column names.  I know the current way makes sense regarding entities as a null column should be null.  But I think you know hwat I mean, I guess I'll check in my object factories where I take entities and turn them into business objects for nulls.  
0
 
aozarovCommented:
>> But I think you know hwat I mean
Yes, I know what you mean but I think this is a dangarous aproach (to have zero in your business layer but null in DB, what will happen when they will set it back...)
If zero is a value that should indicate "empty" then don't set your DB colum to NOT NULL. (or at least don't tell that to the CMP layer [if you are read-only CMP]).
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now