Below are the main parts of the custom type DateTimeType and the mapping file for the table (the table has 2 columns, CREATEDATE and CREATETIME, both of type DATE). You will notice that DateTimeTYpe converts data for the DateTime class. Perhaps you can see something wrong?
Extract from table mapping file
============================================================
<property
name="dateTime"
type="com.lbss.framework.persistence.DateTimeType">
<column name="CREATEDATE"/>
<column name="CREATETIME"/>
</property>
DateTimeType.java (custom type)
============================================================
public class DateTimeType implements UserType {
public DateTimeType() {
if (log.isDebugEnabled()) {
log.debug("DateTimeType constructor called");
}
}
public int[] sqlTypes ()
{
return types;
}
public Class returnedClass ()
{
return com.lbss.framework.DateTime.class;
}
public boolean equals (Object x, Object y) throws HibernateException
{
if (x==y) return true;
if (x==null || y==null) return false;
return ((com.lbss.framework.DateTime)x).equals( (com.lbss.framework.DateTime) y);
}
public Object nullSafeGet (ResultSet rs,
String[] names,
Object owner)
throws HibernateException,
SQLException
{
java.util.Date theDate = (java.sql.Date)Hibernate.DATE.nullSafeGet(rs, names[0]);
java.util.Date theTime = (java.sql.Date)Hibernate.DATE.nullSafeGet(rs, names[1]);
// TODO: Verify this
if ((theDate == null) && (theTime == null))
return null;
System.out.println("DATETIMETYPE: java.util.Date DATE: " + theDate.toString());
System.out.println("DATETIMETYPE: java.util.Date TIME: " + theTime.toString());
// Convert the sql date and time to Vectus Date and Time, and make into a Vectus DateTime object
com.lbss.framework.Date returnDate = new com.lbss.framework.Date(theDate.getTime());
com.lbss.framework.Time returnTime = new com.lbss.framework.Time(theTime.getTime());
System.out.println("DATETIMETYPE: java.util.Date DATE: " + theDate.toString());
System.out.println("DATETIMETYPE: java.util.Date TIME: " + theTime.toString());
com.lbss.framework.DateTime returnDateTime = new com.lbss.framework.DateTime(returnDate, returnTime);
return returnDateTime;
}
public void nullSafeSet(PreparedStatement st,
Object value,
int index)
throws HibernateException,
SQLException {
java.sql.Date setDate = null;
java.sql.Date setTime = null;
if (value != null) {
// Convert the given object into a SQL Date, so that Hibernate can
// handle the statement preparation
com.lbss.framework.DateTime dateTime = (com.lbss.framework.DateTime) value;
com.lbss.framework.Date theDate = dateTime.getDate();
com.lbss.framework.Time theTime = dateTime.getTime();
GregorianCalendar cvtDate = new GregorianCalendar(theDate.year(),
theDate.month(),
theDate.day());
GregorianCalendar cvtTime = (GregorianCalendar)theTime.getCalendar();
setDate = new java.sql.Date(cvtDate.getTimeInMillis());
setTime = new java.sql.Date(cvtTime.getTimeInMillis());
}
// Actually prepare the statement
Hibernate.DATE.nullSafeSet(st, setDate, index);
Hibernate.DATE.nullSafeSet(st, setTime, index + 1);
}
public Object deepCopy (Object value) throws HibernateException
{
if (value == null)
return null;
//com.lbss.framework.Date copy = new com.lbss.framework.Date((com.lbss.framework.Date)value);
com.lbss.framework.DateTime copy = new com.lbss.framework.DateTime(((com.lbss.framework.DateTime)value).getDate(), ((com.lbss.framework.DateTime)value).getTime());
return copy;
}
public boolean isMutable () {
return true;
}
private static final Log log = LogFactory.getLog(DateTimeType.class);
private static final int[] types = {Types.DATE, Types.DATE};
}
|