I agree with you Steve, it should theorically work. But still I get this ClassCastEx from the Timestamp.compareTo(Date)
Here's the JDK impl. of Timestamp.compareTo().
Code:
/**
* Compares this <code>Timestamp</code> object to the given
* <code>Date</code>, which must be a <code>Timestamp</code>
* object. If the argument is not a <code>Timestamp</code> object,
* this method throws a <code>ClassCastException</code> object.
* (<code>Timestamp</code> objects are
* comparable only to other <code>Timestamp</code> objects.)
*
* @param o the <code>Date</code> to be compared, which must be a
* <code>Timestamp</code> object
* @return the value <code>0</code> if this <code>Timestamp</code> object
* and the given object are equal; a value less than <code>0</code>
* if this <code>Timestamp</code> object is before the given argument;
* and a value greater than <code>0</code> if this
* <code>Timestamp</code> object is after the given argument.
*
* @exception ClassCastException if the argument is not a
* <code>Timestamp</code> object
* @since 1.5
*/
// This forwarding method ensures that the compareTo(Date) method defined
// in java.util.Date is not invoked on a Timestamp
public int compareTo(java.util.Date o) {
return compareTo((Timestamp)o);
}
I'm not sure why the've chosen this way but I'm not going to discuss it. I kind of understand that a Timestamp has to be compared with a Timestamp and not a superclass of it.
I'm almost certain that I did have instance of java.util.Date for my properties mapped with this type in the past. Moreover those ClassCastEx appeared after our migration to Hibernatev3.x.
And this actually makes some sense to me, otherwise the type choice between Timestamp and Date wouldn't be left to the user.
If type="java.util.Date" maps to the org.hibernate.type.TimestampType, then what maps to org.hibernate.type.DateType??