You can build a user type that maps ints from the legacy database to BigDecimal with the proper scale. You do not have to change your code at all. Here is what you can do in a class extending UserType:
Code:
public int[] sqlTypes() {
return new int[] { Types.INTEGER };
}
public Class returnedClass() {
return BigDecimal.class;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
Integer tmp = (Integer) Hibernate.INTEGER.nullSafeGet(rs, names[0]);
return ... // Convert tmp.intValue() to BigInteger, apply the scale, and return
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
BigDecimal tmp = (BigDecimal)value;
Integer valueToSet = ... // Convert tmp to int, scaling it back
Hibernate.INTEGER.nullSafeSet(st, valueToSet, index);
}
This should do the trick - I hope this helps.