Reputation: 463
My SQL query is "SELECT productid,FORMAT(AVG(score),2) FROM product GROUP BY productid"
I am getting output as
1001 : 2.23,
1002 : -2.69
In Hibernate my query will be "SELECT product.productId,FORMAT(AVG(product.score),2) FROM ProductDAO product GROUP BY product.productId"
But the format function not supported in hibernate, is there any way to achieve decimal precision in hibernate?
Upvotes: 0
Views: 647
Reputation: 306
In Hibernate you can achieve the decimal precision by specifying the precision & scale property in hbm mapping.
But in your case as you are using AVG function, hence above approach will not work. You can collect the value of AVG(score) in BigDecimal & use setScale method of the BigDecimal.
aNumber.setScale(2, RoundingMode.HALF_UP);
Upvotes: 1