thank's i'm testing my UserType now,because I thought that Hibernate used alone UserType to receive the data but that it didn't ignore it in update/insert.
I have made this change but don't work can you help me?
Devis
Code:
package dao.hibernate;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.*;
import org.hibernate.usertype.*;
import java.io.Serializable;
/**
* @author Colin Hawkett
*/
public class TrimmedString implements UserType,Serializable
{
public TrimmedString() {
super();
}
public int[] sqlTypes() {
return new int[] { Types.VARCHAR };
}
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() : "";
}
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 int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
public Object assemble(Serializable cached, Object owner)
throws HibernateException {
return cached;
}
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}
public Object replace(Object original, Object target, Object owner)
throws HibernateException {
return original;
}
}