gpt4 book ai didi

java - 避免检索带有 "Delete date"的项目

转载 作者:行者123 更新时间:2023-12-01 11:11:02 25 4
gpt4 key购买 nike

我有这两个实体,当我检索人员实体时,该集合仅包含没有删除日期的人员,JPA对此有任何注释吗?现在我正在使用 JPA Api 从数据库检索数据

@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>();
}

最佳答案

使用 Hibernate,一种方法是将 @Where 注释放在人员集合上

@OrderBy("id")
@Where(clause = "delete_date is null")
@OneToMany(mappedBy = "people", fetch = FetchType.EAGER)
private Set<Person> persons = new HashSet<Person>();

关于java - 避免检索带有 "Delete date"的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32369814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com