(I’m using Oracle and JPA (from Java EE 5, WebSphere 7)).
I have a Project class, Project has a list of Tasks.
Each Task has a sequence number so I can determine the task’s sequential order (Task.seq), and a assigned user (Task.userId), and a String status Task.status (“IN_PROGRESS” or “COMPELTE”). The tasks for a project get “COMPLETED” by their assigned user in their numerical sequence.
My problem is … this is the tricky bit … I need a query that does the following:
Given a userid, find all Projects where the current task of that project is assigned to the user. (The ‘current task’ is the first task found in numerical sequence that has a status of “IN_PROGRESS”.)
I’m not great with SQL, and pretty new to JPA — please help!
PS. For example, here’s the query I’m currently using that gets me all Project objects with the task list populated:
select distinct p from Project p left join fetch p.taskList
Any help is greatly appreciated!
Rob
To think about this, start by finding the first task for the user. Then, join in the project information, and select whatever you want to know about the projects:
I’m assuming the task has a projectid, although you don’t explicitly say that.
This solution should work in just about any database.