org.hibernate.exception.ConstraintViolationException:hql请求语法

时间:2016-10-11 20:16:03

标签: hibernate

我有一张名为Champ的桌子, 我想在int i之后将所有id递增1, 当然idChamp是主键

public void increase(int i){

   Query query=factory.getCurrentSession().createQuery("UPDATE Champ c set c.idChamp=c.idChamp+1 WHERE c.idChamp>= :var ORDER BY DESC");
     query.setParameter("var",i+1);         
     int result=query.executeUpdate();
     System.out.println(result);
                                }

我也试过这个

   @SuppressWarnings("unchecked")
    public void increase(int i){

         String hql = "from Champ c WHERE c.idChamp>=:num ORDER BY DESC";
         List<Champ> lesChamps = ( factory.getCurrentSession().createQuery(hql)
         .setParameter("num", i)).list();
         for (Champ c: lesChamps){
             c.setIdChamp(c.getIdChamp()+1);
         }
                                }

0 个答案:

没有答案