JPA Left Join正在生成返回太多行的SQL

时间:2018-05-07 13:13:24

标签: java mysql hibernate jpa

无论export default { component: App, path: '/', indexRoute: { component: Login }, childRoutes: [ { path: 'dashboard', getComponent(location, cb) { System.import('./components/dashboard/Dashboard') .then(module => cb(null, checkAuth(module.default))); } }, { //... another route }, //.. ] }是否与skill相关联,我都需要每skill行一行。有< user中有1000行。但是,JPA / Hibernate生成的SQL为所有用户返回skill行。

JPA

skill

我编写的SQL

select case when su = :user then 1 else 0 end from Skill s left join s.skillUsers su on su = :user order by s.id

由Hibernate / JPA生成的SQL不起作用

select case when us.user_id = 1 then 1 else 0 end from skill as s left join user_skills as us on us.skill_id = s.id and us.user_id = 1

技能实体

select case when user2_.id=? then 1 else 0 end as col_0_0_ from skill skill0_ left outer join user_skills skillusers1_ on skill0_.id=skillusers1_.skill_id left outer join user user2_ on skillusers1_.user_id=user2_.id and (user2_.id=?) order by skill0_.id

用户实体

@BatchSize(size = 100)
@ManyToMany(mappedBy = "userSkills")
@LazyCollection(LazyCollectionOption.EXTRA)
public Set<User> getSkillUsers() {
    return skillUsers;
}

0 个答案:

没有答案