This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate not deleting rows

 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to delete rows from database using hibernate. It is returning the row count of the number of rows deleted, when I go to database the rows are still existing

Here was my query


My code is


 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I change that to <sql-query> as below I am getting the following error




SEVERE: Update queries only supported through HQL

With <query> I am getting the following error





SEVERE: could not execute update query
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Begin a transaction before you delete the rows and then commit the transaction after the rows are deleted, this should do it
 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added Transaction statement

Transaction transaction = session.beginTransaction();
//code to delete rows
transaction.commit();

This time I am getting that the rows are being deleted, but they are not getting deleted. I tried to deleted the row using jdbc code. The row is getting deleted.
 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solution given by Ankit Garg is working fine. I commited a mistake, and it is working fine now. Thanks Ankit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic