Hibernate 3 SQL update using createSQLQuery?
Posted on 2005-04-07
I want to execute a SQL UPDATE using createSQLQuery. However, when I run executeUpate() it gives the exception:
java.lang.RuntimeException: java.lang.UnsupportedOperationException: 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");
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.