【问题标题】:hibernate query java.lang.IllegalArgumentException: node to traverse cannot be nullhibernate查询java.lang.IllegalArgumentException:要遍历的节点不能为null
【发布时间】:2015-08-01 12:22:47
【问题描述】:

在我的休眠查询中,我有:

public void updateStudent(Student student) {


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

        sessionFactory.getCurrentSession().createQuery(hql);

    }

这里我想设置student表的article value=null and id=2..但是

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()

我做错了什么??

【问题讨论】:

标签: java hibernate spring-mvc hql


【解决方案1】:

正如@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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-14
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多