Hibernate version: 3.1.2
We are using a UserType for non-default timezone dates as described in
http://www.hibernate.org/100.html.
Everything is working fine except when querying the attribute via HQL
named parameter.
The Problem is either that the UserType can NOT be passed
as (third) parameter of method org.hibernate.Query.setParameter
(since a org.hibernate.usertype.UserType is not a org.hibernate.type.Type)
or that the user type is not considered by org.hibernate.loader.hql.QueryLoader while binding parameters.
As a workaround we've wrapped the UserType as Type where the
sole real implemented method is nullSafeSet that delegates to
nullSafeSet of the user type and pass the wrapped type, i.e.
query.setParameterList(name, vals, new WrappedUserTypeQueryParameterType (new HibernateUTC.TimestampType ())
and
class WrappedUserTypeQueryParameterType implements Type {
private final UserType wrappedType;
//...
/**
* @see Type#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int,
* org.hibernate.engine.SessionImplementor)
*/
public void nullSafeSet (PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException
{
this.wrappedType.nullSafeSet (st, value, index);
}
}
rather
query.setParameterList(name, vals, Hibernate.TIMESTAMP)
Is there a better solution, did we miss something, or is this a lack/bug of Hibernate?
Thanks for any help, suggestions or comments!