Hi
I haven't experience in oracle db . But i know there are two dates type "DATE" and "TIMESTAMP" . default format for "DATE" is "DD-MON-YY".so it is not a problem.
If you want to get date part of the datevalue you can use usertype
like this.
package lk.wts.test;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
public class DateUserType implements UserType {
private static final int[] TYPES = {Types.DATE};
SimpleDateFormat shortDate=new SimpleDateFormat("dd/MMM/yyyy");
public int[] sqlTypes() {
return TYPES;
}
public Class returnedClass() {
return Date.class;
}
public boolean equals(Object arg0, Object arg1) throws HibernateException {
if (arg0 instanceof Date) {
Date date1 = (Date) arg0;
if (arg1 instanceof Date) {
Date date2 = (Date) arg1;
if(shortDate.format(date1).equalsIgnoreCase(shortDate.format(date2))){
return true;
}
}
}
return false;
}
public int hashCode(Object arg0) throws HibernateException {
return arg0.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object arg2)
throws HibernateException, SQLException {
java.sql.Date date = (java.sql.Date)Hibernate.DATE.nullSafeGet(rs, names[0]);
try {
return shortDate.parse(shortDate.format(date));
} catch (ParseException e) {
throw new HibernateException(e.getMessage());
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
java.util.Date dateTime = (value==null) ? new java.util.Date() : (java.util.Date)value;
Hibernate.DATE.nullSafeSet(st, dateTime, index);
}
public Object deepCopy(Object value) throws HibernateException {
if (value==null) return null;
return new java.util.Date(((java.util.Date)value).getTime());
}
public boolean isMutable() {
return false;
}
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) deepCopy(value);
}
public Object assemble(Serializable value, Object arg1)
throws HibernateException {
return deepCopy(value);
}
public Object replace(Object arg0, Object arg1, Object arg2)
throws HibernateException {
return deepCopy(arg0);
}
}
<property name="logindate" type="lk.wts.test.DateUserType">
<column name="LoginTime" sql-type="date" not-null="true"/>
</property>
First check your datatype in oracle DB then try this user type
Amila
|