Using JPA, I want to select all Log objects for a specific actiontype. From the log object I want to get the user (log.getUser()), but the users appear several times in the result list. I tried it with distinct, but it did not work, I guess because I was not able to define, what exactly has to be distinct. Here is my JPA query:
SELECT DISTINCT log
FROM Log AS log JOIN log.action AS action
JOIN log.user AS user
WHERE action.actionType = :actionType
If I say SELECT DISTINCT user, then I don’t have the whole log object in the end.
Any help or hint would be appreciated.
Edit:
Part of my Log Class:
public class Log {
private int logId;
private Calendar logDate;
private User user;
private Action action;
private String description;
....
}
Two Queries Solution
Since you want
Logobjects anddistinct Userobjects you could do two queries, first one to retrieve theLogobjects and second one to retrievedistict Userobjects.With this approach you have the distinct users for the select
Logs objects.