gpt4 book ai didi

java - 将子查询转换为 jpql 中的连接

转载 作者:行者123 更新时间:2023-11-30 09:52:51 27 4
gpt4 key购买 nike

我有两个类(class) ClassA 和 ClassB。许多 ClassB 可以与单个 ClassA 关联,因此从 ClassB 到 ClassA 是多对一的关系。关系是这样的:

ClassA {
@ManyToOne(optional = false)
@JoinColumn(name = "ClassB_ID", referencedColumnName = "ID", nullable = false)
private ClassB classB = new ClassB();
}

我有这样的查询:

delete from ClassA as a 
where a.classB in (select b from ClassB as b where b.attr1=?1 and b.attr2=?2)
and a.attr3=?3

我将此查询转换为:

delete from ClassA as a join a.classb as b where b.attr1=?1 and b.attr2=?2
and a.attr3=?3"

当我运行它时,我得到以下异常:

ERROR PARSER    - line 1:28: unexpected token: join

org.springframework.dao.InvalidDataAccessApiUsageException:

node to traverse cannot be null!; nested exception is java.lang.IllegalArgumentException: node to traverse cannot be null!

有人可以帮忙吗?

谢谢。

最佳答案

您不能从 JOIN 中删除。您为什么要重写 DELETE 语句?

关于java - 将子查询转换为 jpql 中的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4107197/

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