首页新闻找找看学习计划

JPA查询问题

0
悬赏园豆:10 [待解决问题]

初学者,遇到一个JPA查询的问题,请大家不吝赐教!

@Entity
@Table(name = "person")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "person_id")
private Long person_id;

@Column(name = "name")
private String name;

@OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
private Set<Skill> skills = new HashSet<>();


/**
 * Returns a set containing all skills owned by this user.
 */
@Override    
public Set<Skill> getSkills() {
    return skills;
}

/**
 * Adds the specified skill to the set of skills owned by this user.
 */
public void addSkill(Skill skill) {
    skills.add(skill);
}

/**
* Required by JPA, should not be used.
*/
protected User() {
}

public User(String name) {
this.name = name;
person_id = BeanFactory.getBean(BusinessIdGenerator.class).generatePerson_id();
}

public Long getPerson_id() {
    return person_id;
}

public void setPerson_id(Long person_id) {
    this.person_id = person_id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}


@Override
public int hashCode() {
    return person_id.hashCode();
}

@Override
public boolean equals(Object object) {
    if (!(object instanceof User)) {
        return false;
    }
    User other = (User)object;
    return this.person_id.equals(other.person_id);
}

@Override
public String toString() {
    return Util.toString(this);
}

}

@Entity
@Table(name = "skills")
public class Skill {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = skill_id")
private Long skill_id;

@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "person_id")
private User user;

@Column(name = "name")
private String name;

/**
 * Required by JPA, should not be used.
 */
protected Skill() {
}

public Skill(User user,Long skill_id) {        
    this.user = user;
    skill_id = BeanFactory.getBean(BusinessIdGenerator.class).generateSkill_id();
}

@Override
public Long getSkill_id() {
    return skill_id;
}

}
现在如果招聘人员想根据一组技能(List<Skill> requiredSkills)来查找符合这些技能中某个/某些技能的一组用户(Set<User> users)该怎么找,可不可以在UserRepository里加入以下这个方法? 如果不可行,有没有什么建议?

List<User> findBySkillsIn(List<Skill> requiredSkills);

jinleiDev的主页 jinleiDev | 初学一级 | 园豆:142
提问于:2019-02-19 17:37
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册