我有这2个实体,当我检索People实体时,Set只包含没有deletedDates的人,JPA有没有这个?现在我使用JPA Api从DB中检索数据
人
@Entity
@Table(name = "person")
public class Person {
@Id
@GeneratedValue
private Long id;
private String name;
private Date deleteDate;
@ManyToOne
private People people;
//Getters and setters
}
人
@Entity
@Table(name = "people")
public class People {
@Id
@GeneratedValue
private Long id;
private String from;
@OrderBy("id")
@OneToMany(mappedBy = "people", fetch = FetchType.EAGER)
private Set<Person> persons = new HashSet<Person>();
}
答案 0 :(得分:1)
使用Hibernate,一种方法是将@Where
注释放在一组人
@OrderBy("id")
@Where(clause = "delete_date is null")
@OneToMany(mappedBy = "people", fetch = FetchType.EAGER)
private Set<Person> persons = new HashSet<Person>();