We have implemeted a UserType to map between booleans in our managed objects and 0 or 1 value in a smallint column in DB2.
The UserType works well and as expected except for the fact that the HQL has to query against the actual value in the db table column, and not the value in the managed object. This is counterintuitive for our developers and is not what we expected from using the UserType.
For example, say we have a managed object like this:
Code:
public class Example
{
....
private boolean flag;
....
}
which is mapped like this
Code:
....
<property name="flag" type="somepackage.BooleanIntegerUserType" column="FLAG_IND" access="field"/>
....
To query this object and refer to this boolean property in the where clause I would expect to be able to do:
Code:
select example from Example as example where example.flag = true
but this does not work. I have to do this instead:
Code:
select example from Example as example where example.flag = 1
Are we misunderstanding the use of the UserType in this case? They are only used to map between objects and columns but are not used in anyway in HQL? It doesn't seem right that in HQL I am querying against the values of properties in my objects, but in this case this is not true - I have to query against values that are in the db?
Is there something we are missing in our UserType implementation?
If this is not possible, it would be a nice improvement in future versions of Hibernate :-)
Thanks,
Kevin Hooke
Hibernate version: 2.1.6
Mapping documents:n/a
Code between sessionFactory.openSession() and session.close():n/a
Full stack trace of any exception that occurs:n/a
Name and version of the database you are using:IBM DB2 UDB 8.1.6
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:[/code]