请求处理失败;嵌套的异常是org.hibernate.QueryException:

时间:2018-06-23 15:31:29

标签: java

@Transactional
@Modifying
public boolean deleteBook(String callno, String studentid) {

    boolean userFounds= false;

    Session session=this.sessionFactory.openSession();
     System.out.println("check update:"+callno);
     System.out.println("check update:"+studentid);


        // delete operation
    String SQL_QUERY2 ="delete from IssueBook where callno= ? and studentid=?"; 

    Query query= session.createQuery(SQL_QUERY2);

     query.setParameter(0, callno).executeUpdate();
     query.setParameter(1, studentid).executeUpdate();
     return userFounds;

    }

我收到500台服务器的异常 在这      query.setParameter(0,callno).executeUpdate();          query.setParameter(1,studentid).executeUpdate();

查看堆栈跟踪:

Request processing failed; nested exception is org.hibernate.QueryException: Expected positional parameter count: 2, actual parameters: [1002] [delete from IssueBook where callno= ? and studentid=?]

1 个答案:

答案 0 :(得分:0)

String SQL_QUERY2 ="delete from IssueBook where callno=:callno and studentid=:studentid";
Query query= session.createQuery(SQL_QUERY2);
     query.setParameter(callno, callno);
     query.setParameter(studentid, studentid);
     return query.executeUpdate();

代码中的问题是executeUpdate(),应在设置所有参数后调用一次。