java Hibernate 错误 IllegalArgumentException:要遍历的节点不能为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13088341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate Error IllegalArgumentException: node to traverse cannot be null
提问by Kevin Meredith
My DELETE
query is failing.
我的DELETE
查询失败。
Here's my code:
这是我的代码:
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();
output:
输出:
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)
回答by Steve Ebersole
You define multiple "query roots" (Person p
and DomainGroup g
), but a DELETE query can have only one such root.
您定义了多个“查询根”(Person p
和DomainGroup g
),但 DELETE 查询只能有一个这样的根。
You want something like:
你想要这样的东西:
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
)
or
或者
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
)
回答by Roman C
If you don't use on delete cascade
feature then you should remove all references to the object before deleting it.
如果您不使用on delete cascade
功能,那么您应该在删除之前删除对对象的所有引用。