简体   繁体   中英

hibernate query java.lang.IllegalArgumentException: node to traverse cannot be null

In my hibernate query I have :

public void updateStudent(Student student) {


        String hql = "update Student set article =:null,id=2" 
                +"where article=:"+ student.getArticle();

        sessionFactory.getCurrentSession().createQuery(hql);

    }

Here I want to set student table's article value= null and 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!

my actual mysql query is:

UPDATE student
SET article='null', id=2
WHERE article='xyz';  here xyz=user.getArticle()

what am I doing wrong??

As @JBNizet mentions in the comment, you need to consult the documentation. But you need something like this to set your parameter.

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

}

PS I cannot understand why you are setting the id of your Student when you appear to be deleting an article value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM