Thursday, March 31, 2011

To supress the class attribute 'sql-timestamp' in xstream

I declared createdate as java.util.date in DTO and in the hibernate mapping its been declared as timestamp. So it is trying to marshal a timestamp while datamember is date.
<createDate class="sql-timestamp"> .... </createDate>

To suppress this, either change the date to timestamp in your dto class or
you may set a java.sql.Timestamp as (another) default implementation for a java.util.Date or
you may remove the class attribute completely, something like

StringWriter writer = new StringWriter();
xstream.marshal(this, new PrettyPrintWriter(writer) {
@Override
public void addAttribute(final String key, final String value) {
if (!key.equals("class")) {
super.addAttribute(key, value);
}
}
});

Thursday, March 24, 2011

problem inserting timestamp into the database

The equivalent hibernate type for Date is date, time, timestamp.

So check your hibernate level of mapping the date fields.
<property name="createDate" type ="timestamp">...</property>