Update several Columns in one Hibernate Query?

Paks picture Paks · Sep 6, 2012 · Viewed 35.4k times · Source

i have the Following HQL:

String hql = "UPDATE Buchung as b " +
             "set STORNO = :Storno " +
             "where ID = :BuchungID";

Is it possible to Update more then one column in a HQL? For Example:

String hql = "UPDATE Buchung as b " +
              "set STORNO = :Storno " +
              "set NAME = :Name " +
               ......  
              "where ID = :BuchungID";

I know how to do that in MSSQL but i dont know how to do that in Hibernate.

Answer

Miroslav Popovic picture Miroslav Popovic · Sep 6, 2012

HQL is no different than SQL in this case. Just use comma to separate columns:

String hql = "UPDATE Buchung as b set " +
          "STORNO = :Storno," +
          "NAME = :Name " +
           ......  
          "where ID = :BuchungID";