I want to execute a SQL UPDATE using createSQLQuery. However, when I run executeUpate() it gives the exception:
java.lang.RuntimeException
: java.lang.UnsupportedOpera
tionExcept
ion: Update queries only supported through HQL
The code is as follows:
Session s = getSession();
Query query = s.createSQLQuery("UPDATE know.ObjTypeCnt set cnt=cnt+:cntToAdd where objType=:objType");
query.setInteger("objType"
,objType.g
etId());
query.setInteger("cntToAdd
",cntToAdd
);
query.executeUpate();
I have to do this in SQL because I need to have the cnt column updated atomically and doing it this way is easier than figuring out how to use the hibernate row locking stuff.
Start Free Trial