I just came across this post, and thought I might be able to help in case you are still having the problem (or just another way of solving the problem). You can create the following UserType which will do the conversion back to java.util.Date:
Code:
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Date;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.UserType;
/**
* This class is used to solve the problem where Hibernate uses java.sql.Timestamp for fields that are
* declared as java.util.Date. DateType maps java.util.Date fields as java.util.Date.
*/
public class DateType implements UserType
{
public Object deepCopy(Object value) throws HibernateException
{
return (Date) value;
}
public boolean equals(Object x, Object y) throws HibernateException
{
if (x == y) {
return true;
}
if (x == null) {
return false;
}
return x.equals(y);
}
public boolean isMutable()
{
return true;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException
{
// Start by looking up the value name
Timestamp timestamp = (Timestamp) Hibernate.TIMESTAMP.nullSafeGet(rs, names[0]);
if (timestamp == null) {
return null;
}
return new Date(timestamp.getTime());
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException
{
Hibernate.TIMESTAMP.nullSafeSet(st, value, index);
}
public Class returnedClass()
{
return Date.class;
}
public int[] sqlTypes()
{
int[] typeList = {Types.TIMESTAMP};
return typeList;
}
}