1 Reply Latest reply on Oct 3, 2006 2:38 PM by monkeyden

    Oracle Number field and boolean

    monkeyden

      Is it possible to expose numeric fields as booleans/Booleans in an annotated Entity Bean or do I need to implement that logic outside of the bean? I'm getting an "invalid column name" exception when attempting to load the Entity but I suspect it's using the return type of the accessor to find the field in the table. I seem to recall ResultSet.getBoolean() translating numeric values correctly but don't know if that translates to EJB3.

      I have the following fields in an Oracle table:

      CONTACT_VIA_EMAIL NUMBER(1) DEFAULT 1
      CONTACT_VIA_MAIL NUMBER(1) DEFAULT 1
      CONTACT_VIA_PHONE NUMBER(1) DEFAULT 1


      The Entity Code
      private Boolean contactViaEmail;
      @Column(name = "CONTACT_VIA_EMAIL", nullable = true)
      public Boolean isContactViaEmail() {
       return contactViaEmail;
      }
      public void setContactViaEmail(Boolean contactViaEmail) {
       this.contactViaEmail = contactViaEmail;
      }
      


      OR
      private Integer contactViaEmail;
      @Column(name = "CONTACT_VIA_EMAIL", nullable = true)
      public Boolean isContactViaEmail() {
       return new Boolean(contactViaEmail.intValue()==1);
      }
      public void setContactViaEmail(Integer contactViaEmail) {
       this.contactViaEmail = contactViaEmail;
      }


        • 1. Re: Oracle Number field and boolean
          monkeyden

          Correction:

          The invalid column error was coming from a non-business method which was not marked with @Transient.

          What Im seeing now, however, is this:

          expected type: java.lang.Integer, actual value: java.lang.Boolean


          though the methods do take Integers

          public void setContactViaPhone(Integer contactViaPhone) {
           this.contactViaPhone = contactViaPhone;
          }
          public void setContactViaEmail(Integer contactViaEmail) {
           this.contactViaEmail = contactViaEmail;
          }


          I have already deleted the tmp and work folders and restarted.