I want to use a standard deviation projection in a query that Im constructing using the criteria API. I can do something simply like this
public class StdDevProjection extends AggregateProjection {
public StdDevProjection(String propertyName) {
super("stddev", propertyName);
}
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
return new Type[] { Hibernate.DOUBLE };
}
}
and then I can use it with my criteria as:
myCriteriea.setProjection(new StdDevProjection(myproperty));
Thats all good. But my problem is that I use HSQLDB for any db unit tests etc, whereas we use Oracle for deployment. The stddev function works perfectly in oracle, but its not there in HSQLDB. HSQLDB has stddev_pop and stddev_samp . So is there someway I can use a different function based on the dialect.
I maybe can extend the HSQL dialect to register the "stddev" to the appropriate HSQL function, but then im not sure how to use an hsql function in a query constructed using the Criteria API.
Any help would be gret.
Thanks