小编典典

删除带有JPA和子查询的条目

sql

我刚刚写了一个sql查询:

DELETE FROM basisgegevens.gm_persoonburgstaat pbs 
WHERE (pbs.ingangsdatum, pbs.id_persoon) in (
  SELECT pbs2.ingangsdatum, pbs2.id_persoon 
  FROM basisgegevens.gm_persoonburgstaat pbs2 
  WHERE pbs2.ingangsdatum = pbs.ingangsdatum 
  AND pbs2.id_persoon = :persoonID 
  AND pbs2.id_persoonburgerlijkestaat > pbs.id_persoonburgerlijkestaat);

我需要将其重写为JPQL,但是在子查询中卡住了外部查询。

public class PersoonBurgerlijkeStaatEntity {
@Column(name = "id_persoonburgerlijkestaat"
private Long identifier;
private Date ingangsdatum;
@ManyToOne
@JoinColumn(name = "id_persoon", referencedColumnName = "id_persoon", nullable = false)
private PersoonEntity persoon;

}

永久实体有一个标识符

有人可以帮我重写吗?

谢谢


阅读 158

收藏
2021-05-16

共1个答案

小编典典

对此不确定,请尝试一下。

DELETE FROM persoonburgstaat person where (person.ingangsdatum, person identifier) in 
    (select p.ingangsdatum, p.identifier from persoonburgstaat p
        left join p.persoon per where per.id_persoon = :persoonID 
        AND per.id_persoonburgerlijkestaa > p.identifier)

左联接将使外部查询

但是要确保发布PersoonEntity实体,因为我认为“
id_persoonburgerlijkestaa”是列的名称,而不是属性,因此查询将基于该列而失败。

2021-05-16