簡體   English   中英

休眠查詢java.lang.IllegalArgumentException:要遍歷的節點不能為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM