hibernate多对多自身映射的查询问题

有个User类,User之间可以互相关注,因此User类下面有个多对多的自身映射,关注者和被关注者
[code="java"]
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "t_user_t_followingUser", joinColumns = { @JoinColumn(name = "user_id") },inverseJoinColumns = { @JoinColumn(name = "followingUser_id") })
public List getFollowingUsers() {
return followingUsers;
}

public void setFollowingUsers(List followingUsers) {
this.followingUsers = followingUsers;
}

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "t_user_t_followedUser", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "followedUser_id") })
public List getFollowedUsers() {
return followedUsers;
}

public void setFollowedUsers(List followedUsers) {
this.followedUsers = followedUsers;
}

[/code]

现在要写一个HQL语句查询出一个User所有的粉丝。
这个HQL该如何写呢?

1个回答

试试
select fu from Users u left join u.followedUsers fu;

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问