Like I posted here we are currently busy replacing the Postgres database with an Oracle database. One issue we encountered was the use of boolean fields in the Postgres database, because there is no such type in the Oracle database. So we chose to create a Varchar2(1) field that contains a 't' or 'f', being 'true' or 'false'.
But since our application has already been written for the biggest part, we are already making use of boolean fields in our Java code. But that's where Hibernate comes to the rescue. We are using Hibernate3 as our ORM framework. With Hibernate it is very easy to convert a boolean in the Java code to a char value in the database by extending the class 'CharBooleanType' to create your own custom type. I have the java code we used for our type here:

JAVA:
  1. package net.pascalalma.hibernate.types;
  2.  
  3. import org.hibernate.type.CharBooleanType;
  4.  
  5. public class TrueFalseType extends CharBooleanType {
  6.  
  7.     protected final String getTrueString() {
  8.         return "t";
  9.     }
  10.  
  11.     protected final String getFalseString() {
  12.         return "f";
  13.     }
  14. }

To use this type in our Entity classes I have defined the type with a package annotation (yes, we are using Hibernate annotations at our project). This package scoped annotation is a nice feature since JDK5 which I hadn't used or seen before. I have created a file 'package-info.java' like this:

JAVA:
  1. @TypeDefs(
  2.   {@TypeDef(name="truefalse-type",typeClass = TrueFalseType.class)}
  3. )
  4. package net.pascalalma.hibernate.entity;
  5.  
  6. import net.pascalalma.hibernate.types.TrueFalseType;
  7. import org.hibernate.annotations.TypeDef;
  8. import org.hibernate.annotations.TypeDefs;

(By the way, I read somewhere that the javadoc generator will take the javadoc in this package-info.java as package javadoc, even if there is also a package.html defined in this package)
Now in the entity classes in the package 'net.pascalalma.hibernate.entity' I can use the defined Type like this:

JAVA:
  1. package net.pascalalma.hibernate.entity;
  2.  
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.Id;
  6. import javax.persistence.Table;
  7.  
  8. import org.hibernate.annotations.Type;
  9.  
  10. @Table(name="MYTABLE")
  11.  
  12. public class MyTable {
  13.  
  14.     Long id;
  15.     Boolean indicator;
  16.     String name;
  17.  
  18.     public String getName() {
  19.         return name;
  20.     }
  21.     public void setName(String name) {
  22.         this.name = name;
  23.     }
  24.     @Id
  25.     @Column(name="ID")
  26.     public Long getId() {
  27.         return id;
  28.     }
  29.     public void setId(Long id) {
  30.         this.id = id;
  31.     }
  32.  
  33.     @Column(name="indicator")
  34.     @Type(type="truefalse-type")
  35.     public Boolean getIndicator() {
  36.         return indicator;
  37.     }
  38.  
  39.     public void setIndicator(Boolean indicator) {
  40.         this.indicator = indicator;
  41.     }
  42. }

And that's it. More changes aren't necessary to solve this issue, so we can continue our conversion untill we run into the next issue :-)