I'm having a N+1 SQL issue with the below setup. I'm not sure how to fix it. I researched on internet and also looked the relevant posts in this forum but I couldn't figure it out how to fix this.
// Snippet DetachedCriteria criteria = DetachedCriteria.forClass(Group.class); criteria.setFetchMode("members", FetchMode.JOIN); criteria.add(Property.forName("usageType").in(usageTypes));
criteria.getExecutableCriteria(...)
// ENTITY setup
@Entity @Table(name = "GROUP", schema = "XYZ") public class Group implements Serializable {
@Id @Column(name = "GROUP_ID") private Long id;
@OneToMany(mappedBy = "groupMemberPK.groupId") private Set<GroupMember> members;
@Column(name = "USAGE_TYP", nullable = false) private String usageType;
}
@Entity @Table(name = "GROUP_MEMBER", schema = "XYZ") public class GroupMember implements Serializable {
@EmbeddedId private GroupMemberPK groupMemberPK;
}
@Embeddable public class GroupMemberPK implements Serializable {
@ManyToOne @JoinColumn(name = "GROUP_ID") private Group groupId;
@Column(name = "MEMBER_ID") private String memberId; }
|