![](/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.