Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Problem with Hql Update

 
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.
 
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
 
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.
 
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.
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic