michael wrote:
Use a custom UserType - see the wiki for examples.
I've uesd the UserType, the my problem is that how cause the age is the premitive type...
my UserType is similar to this.
Code:
public class MyUserType implements UserType {
private static final int[] SQL_TYPES = {Types.VARCHAR};
public int[] sqlTypes() {
// TODO Auto-generated method stub
return SQL_TYPES;
}
public Class returnedClass() {
// TODO Auto-generated method stub
return int.class;
}
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
if(resultSet.wasNull())
return null;
String string = resultSet.getString(names[0]);
return new Integer(string);
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
if(value == null){
st.setNull(index, Types.VARCHAR);
}else{
Integer date = (Integer)value;
st.setString(index, date.toString());
}
}
......
}
The problem is the the nullSaftGet method can not get the correct resultSet...