This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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.
 
Gerald Vormbrock
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the hbm you wrote name="code.Book", it is the name to use.
You should set name="book" and it should work.
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!