gpt4 book ai didi

java - hibernate 错误 IllegalArgumentException : node to traverse cannot be null

转载 作者:行者123 更新时间:2023-11-29 07:11:58 30 4
gpt4 key购买 nike

我的 DELETE 查询失败了。

这是我的代码:

String q = "SELECT p.id FROM Person p, DomainGroup g WHERE 
p member of g.coordinators" + " AND g.id = :groupId
AND p.id = :personId";

List<Long> test = getEntityManager()
.createQuery(q).setParameter("groupId", followingId)
.setParameter("personId", followerId).getResultList();

log.debug("test = " + test);

String deleteGroupCoordinatorQuery =
"DELETE FROM Person p, DomainGroup g WHERE p member
of g.coordinators" + " AND g.id = :groupId
AND p.id = :personId";

List<Long> test = getEntityManager()
.createQuery(deleteGroupCoordinatorQuery).setParameter
("groupId", followingId)
.setParameter("personId", followerId).executeUpdate();

输出:

test = [1,2,3]

2012-10-26 13:44:56,437 ERROR org.company.commons.server.service.ServiceActionController - Error occurred performing transaction. java.lang.IllegalArgumentException: node to traverse cannot be null!
at org.hibernate.hql.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:55)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:280)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)

最佳答案

您定义了多个“查询根”(Person pDomainGroup g),但是 DELETE 查询只能有一个这样的根。

你想要这样的东西:

delete Person p
where p.id in (
select c.id
from DomainGroup g
join g.coordinators c
where g.id = :groupId
and c.id = :personId
)

delete Person p
where p.id = :personId
and p.id in (
select c.id
from DomainGroup g
join g.coordinators c
where g.id = :groupId
)

关于java - hibernate 错误 IllegalArgumentException : node to traverse cannot be null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13088341/

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