4 Replies Latest reply on Aug 14, 2003 12:24 PM by Amit Kirdatt

    int nullable

    Amit Kirdatt Newbie

      DB: Oracle9i
      JBoss: Jboss3.2.1-tomcat4.1.24
      JDK: IBMJDK-1.3.1

      We have a column which is Number(10) in our database and is nullable. When the column is null we get a NullPointerException. I looked thru the forums here and it has been advised not to use primitive types for nullable columns. The JDBC spec certainly allows for this, as far as I know, so why this behaviour in JBoss? Is there a way to avoid this by tweaking config files?

        • 1. Re: int nullable
          Stephen Coy Novice

          I am assuming that you are talking about CMP entity beans here:

          How do you assign null to a primitive type?

          Since it is not legal to write:

          int i = null;

          you must use a java.lang.Integer instead.

          Steve Coy

          • 2. Re: int nullable
            Amit Kirdatt Newbie

            I understand what you are saying completely however I was thinking that if it is possible in the JDBC API (getInt() returns 0 if null) shouldn't we consider it implementing it in JBoss, or is it some kind of spec violation to do so, or goes agains't some philosophy?
            If so, then somebody please post their response here as I would like to learn, understand and gain an insight into what other people think on this topic.

            • 3. Re: int nullable
              Stephen Coy Novice

              Well, aside from the fact that this behavior is mandated by the spec, there is no formal relationship between JDBC and CMP.

              Most implementations will use JDBC to access database tables, but there is nothing in the rule book that says this must be so. An implementation could, for example, use a JNI interface and the Oracle Call Interface if it wanted.

              The only way a CMP implementation has of transmitting the fact that a column is NULL is to return null to the user. The behaviour that you desire is trivial to implement in your own entity bean.

              Steve Coy

              • 4. Re: int nullable
                Amit Kirdatt Newbie


                Thank you for your reponse.
                I have already implemented the change in my EntityBean. I was only asking the questions above for my own good, so that I could better understand what I am doing.

                Thanks so much, again!!