Hibernate, HSQL, Native Queries and Booleans
I use an in-memory HSQL Database in order to test my JPA/Hibernate Application. Common thing. That explains my surprise on the following situation: I have an Entity with a boolean member:
@Entity public class Foo{ @Id int id; boolean bar; [..] }
Everything works as expected up to here. But then, i use a native query like this:
SELECT id,bar FROM Foo f
Imagine the look of my face when i got this in response:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 16
while Type 16 is boolean. WTF? After a little digging, the Hibernate-Dialect is found to be incomplete, for it does not know
how to map booleans in native queries’
I don’t get it. I cannot be the first guy running into this. Anyway, i’ll file a bug for the hibernate guys (let’s see if they smack me down for that) and wait and see.
Until then, you can easily work around this by using this extension:
public class CustomHSQLDialect extends org.hibernate.dialect.HSQLDialect
{
public CustomHSQLDialect()
{
registerColumnType(Types.BOOLEAN, "boolean");
registerHibernateType(Types.BOOLEAN, "boolean");
}
}
and then use this Dialect in you persistence.xml instead of org.hibernate.dialect.HSQLDialect.


I hit this issue on my very first attempt to issue a native query via session.createSQLQuery(…).
Thanks to the fix above I was able to proceed with my second attempt – whereapon I discovered that the results returned for all the char(32) columns (UUIDs) only have a single Character with but the first digit of the uuid.
heh the funny thing is that when using standard JPQL everything works fine but switching to nativequery…. well bum
Thanx. Helped a lot.