-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: N+1 sql issue
PostPosted: Mon Mar 14, 2011 5:24 pm 
Newbie

Joined: Mon Mar 14, 2011 5:10 pm
Posts: 1
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;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.