![](/img/trans.png)
[英]Hibernate query giving java.lang.IllegalArgumentException: node to traverse cannot be null
[英]hibernate query java.lang.IllegalArgumentException: node to traverse cannot be null
在我的休眠查询中,我有:
public void updateStudent(Student student) {
String hql = "update Student set article =:null,id=2"
+"where article=:"+ student.getArticle();
sessionFactory.getCurrentSession().createQuery(hql);
}
在这里我想设置学生表的文章值= null和id = 2 ..but
every time an error is occurring:
node to traverse cannot be null!
Caused by:
java.lang.IllegalArgumentException: node to traverse cannot be null!
我实际的mysql查询是:
UPDATE student
SET article='null', id=2
WHERE article='xyz'; here xyz=user.getArticle()
我究竟做错了什么??
正如@JBNizet在评论中提到的那样,您需要查阅文档。 但是您需要这样的设置参数。
public void updateStudent(Student student) {
String hql = "update Student set article = null, id = 2"
+ " where article = :article";
sessionFactory.getCurrentSession()
.createQuery(hql)
.setParameter("article", student.getArticle()) ... etc
}
附言:当您似乎要删除文章值时,我无法理解为什么要设置学生ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.