Update several Columns in one Hibernate Query?

前端 未结 3 2284
渐次进展
渐次进展 2021-02-19 08:01

i have the Following HQL:

String hql = \"UPDATE Buchung as b \" +
             \"set STORNO = :Storno \" +
             \"where ID = :BuchungID\";
3条回答
  •  广开言路
    2021-02-19 08:20

        String hql = "UPDATE Buchung as b set " +
              "STORNO = :Storno," +
              "NAME = :Name " +
               ......  
              "where ID = :BuchungID";
    
    Query qr = session.createSQLQuery(hql);
    
    qr.setParameter("Storno","sto_value");
    
    qr.setParameter("Name","name_value");
    
    ...
    
    qr.executeUpdate();
    

    in normal, you must have "transaction" to run query

        Transaction transaction = null;
    transaction = session.begintransaction();
    ...
    transaction.commit();
    

提交回复
热议问题