-->
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.  [ 4 posts ] 
Author Message
 Post subject: execute "UPDATE category SET lft = lft + 2 WHERE lft &
PostPosted: Thu May 05, 2005 9:03 am 
Newbie

Joined: Thu May 05, 2005 8:48 am
Posts: 4
Dear all

I dont know is this the place to ask this question. I tried the CreateQuery() function and named query option and all, but it failed.


can Anybody help me saying how to execute the query
"UPDATE category SET lft = lft + 2 WHERE lft >2"


ofcourse I dont want to select all the entries and execute one by one,
I am looking for a single executeUpdate()

thanks and regards
boolee

Hibernate version:3




Name and version of the database you are using:Mysql 3.x


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 9:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
"it failed" is not a sufficient description of your problem.


Top
 Profile  
 
 Post subject: want a code sample
PostPosted: Thu May 05, 2005 11:26 pm 
Newbie

Joined: Thu May 05, 2005 8:48 am
Posts: 4
michael wrote:
"it failed" is not a sufficient description of your problem.



sorry.. i was thinking that somebody might post a codesample for that.

Below is the code i used
Code:
   String hqlUpdate = "update Category set lft = lft + 2 where lft >2 ";
   Query q = session.createQuery( hqlUpdate );
   int updatedEntities = q.executeUpate();



it gave me an error

root0_0_, this_.name as name0_0_, this_.lft as lft0_0_, this_.rgt as rgt0_0_ from nested_category t
his_ where this_.rgt=? and this_.lft=? and this_.name=?
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: expecting DOT, found '=' near lin
e 1, column 25 [update Category set lft = lft + 2 where lft >2 ]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:74)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:214)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
................................................

can anyone pls give me a code sample for executing the query

thanks
boolee


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 12:03 am 
Newbie

Joined: Thu May 05, 2005 8:48 am
Posts: 4
I tried the modified query

Code:

   String hqlUpdate = "UPDATE Category  c SET  c.lft =  c.lft+2 WHERE  c.lft > 2  ";
   Query q = session.createQuery( hqlUpdate );
    int updatedEntities = q.executeUpate();



it gave the error

Quote:
Hibernate: update nested_category category0_ set category0_.lft=category0_.lft+2 where (category0_.l
ft>2)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)


the mysql query details produced is

Quote:
Caused by: java.sql.SQLException: Syntax error or access violation, message from server: "You havean error in your SQL syntax near 'category0_ set category0_.lft=category0_.lft+2 where (category0_.lft>2)' at line 1"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.