Quote:
select sum(price) from spot where job_id=? and id in (select id from status where job_id=? group by spot_event_id)
A join-query might be more performant.
Something like:
Code:
select sum(price) from spot , status
WHERE spot.job_id = status.job_id AND spot.id=status.id AND spot.job_id = ?
Quote:
Should i create the query with Query query = session.createQuery?
For Querying scalar values I personally prefer session.createSQLQuery
Quote:
what does it mean setCacheable on the query?
It puts the result into Second Level cache if you properly configure the Second Level cache.
Second Level cache is optional and may increase the performance of your application.
Quote:
when can i flush this cacheable?
What do you mean with 'flushing the cacheable' ?
Do you mean evict?