用HQL本身寫了個update!!!

原來代碼:session

public void updateSj(String jsly, Integer zu,String sj) {
        if (!StringUtils.isBlank(jsly)&&null!=zu&&!StringUtils.isBlank(sj)) {
            Session session = sessionFactory.getCurrentSession();
//            session.beginTransaction();
//            SQLQuery query = session.createSQLQuery("UPDATE cq_num SET sj=:sj WHERE jsly=:jsly AND zu=:zu");
//            query.setParameter("jsly", jsly);
//            query.setParameter("zu", zu);
//            query.setParameter("sj", sj);
//            query.executeUpdate();
//            session.getTransaction().commit();
            Query query = session.createQuery("UPDATE CqNum SET sj=? WHERE jsly=? AND zu=?");
            query.setString(0, sj);  
            query.setString(1, jsly);  
            query.setLong(2, zu);
            query.executeUpdate();
        }
    }

 

其中:spa

Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();
            SQLQuery query = session.createSQLQuery("UPDATE cq_num SET sj=:sj WHERE jsly=:jsly AND zu=:zu");
            query.setParameter("jsly", jsly);
            query.setParameter("zu", zu);
            query.setParameter("sj", sj);
            query.executeUpdate();
            session.getTransaction().commit();

也能更新,可是太慢啦!!!(session.beginTransaction();和session.getTransaction().commit();去掉)code

 

修改後代碼:blog

Query query = session.createQuery("UPDATE CqNum SET sj=? WHERE jsly=? AND zu=?");
            query.setString(0, sj);  
            query.setString(1, jsly);  
            query.setLong(2, zu);
            query.executeUpdate();

OK!!!!!!!get

相關文章
相關標籤/搜索