Reputation: 907
I have a situation with a unidirectional @ManyToOne association which I need to query eagerly from the other side with querydsl-jpa (additional to grouping and calculating).
public class Skill implements java.io.Serializable {
...
@NotNull
@ManyToOne
private Profile profile;
private int level;
...
}
Now I'd like to get all Profiles sorted by the sum of their skill-levels and their Skills
final QProfile profile = QProfile.profile;
final QSkill skill = QSkill.skill;
return from(profile, skill)
.where(skill.profile.eq(profile))
.where(...)
.groupBy(profile.id)
.list(profile);
...will find the profiles correctly, but I need as well their skills (and their overall level).
My current workaround is to fetch all (skills and profiles) into a list of result-objects, then grouping skills to profiles and calculating their overall level
Any clues?
Upvotes: 1
Views: 709
Reputation: 22190
Using OneToMany from Profile to Skill with mappedBy would be a solution here.
public class Profile {
@OneToMany(mappedBy = "profile")
private List<Skill> skills;
}
Upvotes: 1