I hope ur porblem is solved already.If not here is what i have done for same problem.
to remove the trimmed string best way is to use UserType . U need to override some methods. I have written as code for the same problem :
Code:
public class NotNullString implements UserType {
public TrimmedString() {
super();
}
public int[] sqlTypes() {
return new int[] { Types.CHAR };
}
public Class returnedClass() {
return String.class;
}
public boolean equals(Object x, Object y) throws HibernateException {
return (x == y) || (x != null && y != null && (x.equals(y)));
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
String val = rs.getString(names[0]);
return val != null ? val.trim() : null;
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
st.setString(index, (String)value);
}
public Object deepCopy(Object value) throws HibernateException {
if (value == null) return null;
return new String((String)value);
}
public boolean isMutable() {
return false;
}
public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
// TODO Auto-generated method stub
return null;
}
public Serializable disassemble(Object arg0) throws HibernateException {
return null;
}
public int hashCode(Object arg0) throws HibernateException {
return 0;
}
public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
return null;
}
}
The nullSafeSet() and nullSafeGet() method is used to set and get the values from the database .