[jboss-user] [EJB 3.0] - Oracle Number field and boolean

monkeyden do-not-reply at jboss.com
Tue Oct 3 13:18:01 EDT 2006


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;
  | }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3975836#3975836

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3975836



More information about the jboss-user mailing list