-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: DB2 and booleans in Hibernate
PostPosted: Mon Oct 02, 2006 11:06 am 
Newbie

Joined: Wed Jul 05, 2006 2:26 pm
Posts: 5
We use DB2 as one of our data sources for our application. We are currently in the process of converting all the JBoss CMP stuff over to raw Hibernate using Spring and annotations. One of the things I consistently run into is the use of ints as booleans. This was done because DB2 lacks a true Boolean type (at least this is what I am told by the DBAs).

I would like to modify the method signatures such that the return a true primative boolean type rather than an int, but I am not sure how to do this.

For instance, we have something like this:
Code:
   @Basic
   @Column (name="PROFILE_ACTIVE")
   public int getProfileActive() {
      return this.profileActive;
   }
   public void setProfileActive(int profileActive) {
      this.profileActive = profileActive;
   }


which I would like to read more like:
Code:
   @Basic
   @Column (name="PROFILE_ACTIVE")
   public boolean isProfileActive() {
      return this.profileActive;
   }
   public void setProfileActive(boolean profileActive) {
      this.profileActive = profileActive;
   }


having Hibernate take care of converting the boolean to a 1 or 0 for me. Is this legal? If I did this, would all hell break looks, or would this actually work even though the underlying database has this column defined as an smallint(5)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 1:03 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
You can use a custom UserType for this conversion. I've done this in DB2 (although we chose to store the value as char(1)). Check the following link in the WIKI for an example that does something similar: http://www.hibernate.org/189.html

Curtis ...[/url]

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.