Advertisement

04.07.2005 at 12:16AM PDT, ID: 21379674
[x]
Attachment Details

Hibernate 3 SQL update using createSQLQuery?

Asked by HappyEngineer in Java Programming Language

Tags: hibernate, update, createsqlquery

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");
        query.setInteger("objType",objType.getId());
        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
[+][-]04.07.2005 at 03:46AM PDT, ID: 13725447

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2005 at 12:10PM PDT, ID: 13730090

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2005 at 12:27PM PDT, ID: 13730231

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.10.2005 at 04:23PM PDT, ID: 13749338

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.10.2005 at 07:03PM PDT, ID: 13749745

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: hibernate, update, createsqlquery
Sign Up Now!
Solution Provided By: aozarov
Participating Experts: 2
Solution Grade: B
 
 
[+][-]05.02.2005 at 02:59PM PDT, ID: 13913337

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32