Q:

Java Hibernate Criteria Average: BigDecimal instead of Double

Hibernate criteria is mapping Projections.avg("column") to Double.
How can I force Hibernate to map that function to BigDecimal?
Hibernate is hibernate-core-4.1.9.Final.jar

A:

Should be possible to subclass AvgProjection override getTypes to return BigDecimal and use this projection instead.
i.e.
public class AvgBDProjection extends AvgProjection{

    public AvgBDProjection(String propertyName) {
        super(propertyName);
    }

    public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
    throws HibernateException {
        return new Type[] { org.hibernate.type.BigDecimalType.INSTANCE };
   }
}

