I found out that I can use hibernate to get the sum of the number of objects using HQL as follows:
public Long getEnvelopeTotal(AbstractEnvelope envelope) {
String query = "select sum(t.amount) from User_Transaction t";
Long result = (Long) hibernateUtil.getSession().createQuery(query).uniqueResult();
return result;
}
Currently, the rest of my application can only navigate through the database through a graphic object. The problem with having to use the above function is that I have to execute the following psuedo code ...
- Get an instance of the Envelope entity
- Skip Envelope i
- By the result, getEnvelopeTotal sets the Envelope instance property "total" for the result.
What interests me is whether it is possible to use sleep mode so that the "total" property is set using a custom HQL query instead of matching with a simple database column.
ex:
@SomeMagicAnnotation(query="select sum(t.amount) from User_Transaction t")
private Long total;
Any suggestions?