This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Hql Update

 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am very new to hibernate. I am trying my hands on HQL. I am trying Updating a table but facing a problem. I will try to explain it in as much detail I can.
First of all I am using netbeans 7.2, Oracle 10G express edition.

(1)The Table called book and its like this:


(2)hibernate.cfg.xml


(3)hibernate.reveng.xml


(4)book.hbm.xml


(5)The POJO class, book.java


(6)And finally, HQLUpdate.java, where the problem occurs
 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I am executing HQLUpdate.java, the following Exception message comes:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: expecting EQ, found ':' near line 1, column 26 [update book set bookname :bname where bookid :bid]

The full output looks like this:


Can you please tell me where is the problem?
Thanks in advance.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with HQL you are using. You are using below query -



while it should be as mentioned below (= operator is missing in your query) -


Kindly try it and let us know if you are still facing any issues
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the last post is still missing a "=", try this ...

 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Emanuel,

Good catch..
The correct hql would be -

 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extremely sorry for replying so late. Thanks to both Salil and Emanuel for replying.
I tried your solution....but an exception is thrown now.
it is saying....Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: book is not mapped [update book set bookname =:bname where bookid =:bid]
The run window says
 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correction. it has been solved. i was using the table name instead of class name.
Thanks for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic