避免使用"删除日期"检索项目。

时间:2015-09-03 07:46:45

标签: java hibernate jpa

我有这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>();
}

1 个答案:

答案 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>();