• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate:Problem in updaing data to the database

 
Midhun Sivasankaran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Please help me on updating the data using Hibernate. I have done the following

String hql = "UPDATE Relation SET frID = frID+1 WHERE projectID = 108";
Query query = session.createQuery(hql);
int rowCount = query1.executeUpdate();

But I'm getting the following error:

query must begin with SELECT or FROM: UPDATE [UPDATE Relation SET frID = frID+1 WHERE projectID = 108]

Thanks,
Midhun
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason you are trying to do this update with HQL? It would be easier to use session.saveOrUpdate.

If you do need to do this with HQL you need to call executeUpdate not executeQuery.
 
Ankit Garg
Sheriff
Posts: 9597
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that he is using executeUpdate. Maybe this could help...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah. Well spotted
 
I'm still in control here. LOOK at this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!