Display
Display

Reputation: 314

HQL: Division inside Criteria Query

This doesn't work in Hibernate, because sum seems to be only able to take in one property: criteria.setProjection(Projections.sum("h.dogs/h.cats"));

How do I rewrite this, without using any native SQL, as a criteria Projection or the like? If I just put h.dogs inside the sum, then that works but I need to divide them.

Upvotes: 0

Views: 983

Answers (1)

Display
Display

Reputation: 314

I found a good solution.

@Formula("dogs / cats")
private double calculation;

in my Object class did the trick, I can then refer to it via

criteria.setProjection(Projections.sum("h.calculation"));

Upvotes: 2

Related Questions