I would be very grateful if someone were to help me with this JPA query. The object structure is simple. I have sessions and I have tasks. I would like to find the latest Task for a given Session.
So far, I have been able to do it with this query:
The problem is that if a session has many tasks (say 30,000 or so) than the query takes a VERY long time to process (30-60 seconds). I would like to optimize the sub-query to get rid of the max statement since that is what is expensive.
I would LIKE to do:
But I guess you cannot do a LIMIT clause in a sub-query. Can anyone think of a more performant solution to my problem?