tags:

views:

1561

answers:

2

How do I map a CHAR(1) to a boolean using Hibernate for Java?

+1  A: 

The true_false or yes_no types will do this for you.

Andrzej Doyle
That's perfect. Thanks! I saw where I could create a UserType, but I figured there was an easier way now, and this was it.
ScArcher2
For example: <property name="deleted" type="yes_no" .../>
Nick Holt
<property name="expired" column="EXPIRED" type="yes_no" />When I do this I get this error , I have my variable as boolean and db type as char(1)[9/30/09 15:25:41:258 PDT] 0000003f SystemErr R at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java:262)[9/30/09 15:25:41:258 PDT] 0000003f SystemErr R at com.ibm.db2.jcc.c.t.a(t.java:16) This is killing me..!!!
Broken Link
+2  A: 

CharBooleanType is probably what you are looking for http://www.hibernate.org/hib_docs/v3/api/org/hibernate/type/class-use/CharBooleanType.html

edit: dtsazza's answer is probably more useful if you just want to get going and use characters y/n or t/f. If those don't match your usage you can implement your own type using CharBooleanType.

Simon Groenewolt
Thanks! I knew I could use a UserType, but I thought there may be a simpler way, and dtsazza gave me what I needed.
ScArcher2