-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: can i use sql "update" using session.createSQLQuer
PostPosted: Wed Mar 14, 2007 10:24 pm 
Newbie

Joined: Wed Mar 14, 2007 10:21 pm
Posts: 1
Hi all,
i got a question, can i use sql "update" using session.createSQLQuery ?

My code is like this :

String sqlQuery = "UPDATE HP_COUNTRIES4MODEL b SET item_id = " +
"NVL((SELECT item_id FROM HP_MODEL_MASTER a " +
"WHERE a.item_name = b.item_display_name), 0)";
Query query = session.createSQLQuery(sqlQuery);
query.uniqueResult();


but it always returning exception :(

can somebody help me ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:43 am 
Newbie

Joined: Thu Mar 15, 2007 10:11 am
Posts: 19
Location: Dallas
if your query is HQL
-----------------------
Query q = s.createQuery("your hql here");
q.setString("coloumn name", value);
q.executeUpdate();

if it is normal sql then
------------------------
SQLQuery query=s.createSQLQuery("your sql here");
query.setString("coloumn name", value);
query.executeUpdate();


Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:58 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
I don't think query.uniqueResult() can be used for executing update-statements. Wouldn't query.executeUpdate() be more appropriate???

Just some wild guess....

Edit: I just did try this.
Using query.uniqueResult() gave a SqlException from the jdbc-Driver saying "executeQuery method cannot be used for update." (just as I suspected).

Using executeUpdate() gave an UnsupportedOperationException saying "Update queries only supported through HQL".

So it seems you'll have to use HQL for update-statenments...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.