java - @EntityGraph 卸载相关实体忽略 @Where 注释
问题描述
我在我的项目中使用软删除。我需要卸载很多相关实体。我同时对多个实体使用@EntityGraph - entityA.EntityB.EntityC,这不适用于相关实体。每个实体都有@Where 注释。我尝试在现场使用 @Where 和 @WhereJoinColumn 实体。它没有给出任何结果
@Entity
@Where(clause = "field is null")
public class EntityA {
@OneToOne(mappedBy = "entityA", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@PrimaryKeyJoinColumn
private EntityB entityB;
@Entity
@Where(clause = "field is null")
public class EntityB {
@MapsId
@OneToOne(fetch = FetchType.LAZY)
private EntityA entityA;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id", referencedColumnName = "id", nullable = false)
private EntityC entityC;
@Entity
@Where(clause = "field is null")
public class EntityC {
@OneToMany(mappedBy = "EntityB")
@Audited(targetAuditMode = NOT_AUDITED)
private Set<EntityB> set = new HashSet<>();
public interface EntityARepository extends JpaRepository<EntityA, Integer> {
@EntityGraph(attributePaths = {"entityB.entityC"})
Optional<EntityA> findById(Integer id);
我希望 Hibernate 向我返回一个查询,例如
SELECT * FROM EntityA
LEFT JOIN EntityB ON EntityA.id = EntityB.id
AND EntityB.field is null
LEFT JOIN EntityC ON EntityB.id = EntityC.id
AND EntityC.field is null
WHERE EntityA.id = ? AND EntityA.field is null
但它回到我身边
SELECT * FROM EntityA
LEFT JOIN EntityB ON EntityA.id = EntityB.id
LEFT JOIN EntityC ON EntityB.id = EntityC.id
AND EntityC.field is null
WHERE EntityA.id = ? AND EntityA.field is null
卸载许多相关实体时,如何让 Hibernate 查看我的所有 @Where 注释。我在hql中写了一个查询,但是太麻烦了。谢谢
解决方案
推荐阅读
- java - Kafka Connect 与 Solace Source 连接器和 JDBC Sink 连接器的问题
- google-play - CodeMagic 错误,无法发布到谷歌商店
- javascript - 如何限制用户直接从 AngularJS (1.x) 中的 URL 访问 html 模板
- java - 试图理解此错误“连接错误尝试在空对象引用上调用虚拟方法'int java.lang.string.indexOf”
- powershell - 使用 Powershell 导出 NTFS 安全权限
- python - 错误:无法在 GCP 上安装自定义包
- javascript - 如何通过 ReactJS 中的函数将数据从一个组件传递到另一个组件?
- linkedin - mediaUpload/uploadedVideo 频繁返回 504 Gateway Timeout
- c# - 如何使用 C# .Net 核心对 CBOR 二进制文档进行 COSE 签名?
- sql-server - 在 TSQL 中没有连接的 SQL 过滤