gpt4 book ai didi

hibernate - 在 Hibernate JPA 中; OneToMany 如何过滤结果;因为我不想删除任何数据

转载 作者:行者123 更新时间:2023-12-03 12:09:07 25 4
gpt4 key购买 nike

我不想在我的 webapp 中执行删除操作。因此,如果记录被删除,我会在所有表中保留一列状态,该列等于 P。默认情况下,我希望在获取记录时这样做;不应获取 status = P 的实体;即应该发生一个额外的 where 子句...... where status = A ;或状态!= P。

使用注释实现它的最佳方法是什么?我当然可以写一个手动查询..

例如:我的用户类可以有多个 child 。我们如何实现以便 user.getChilds() 不返回状态为 P 的 child

User.java
@OneToMany( mappedBy = "usr",
targetEntity = Child.class,
fetch = FetchType.EAGER,
cascade = CascadeType.ALL )
@OrderBy( "fullName ASC" )
List<Child> childs;

Child.java:
@ManyToOne
@JoinColumn
User usr;

最佳答案

使用 Hibernate filters ,或附加 where clause .过滤器可以在运行时被激活和参数化,而 where 子句不能。但它们都用于将额外的 where 子句应用于持久集合。

关于hibernate - 在 Hibernate JPA 中; OneToMany 如何过滤结果;因为我不想删除任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10774664/

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