Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate row deleted msg received but not reflected in DB

 
Maya sekar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
I was trying to delete a row using HQL. The code is as follows.



When I run the program,

The output is as follows,


though it says 1 row deleted, the change is not reflected in the db. I don't understand why. Can someone please explain to me why this happens and how i can fix it.

thank you.
Have a nice day.
 
Madhavi Subramaniam
Ranch Hand
Posts: 33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maya,

Have you checked the other DB operation save and Edit also getting updated in database or not?

If those are reflected in your data base, delete also should work fine.

Or try flush() method.

you will need to flush or else the changes won't be reflected in the db when the SQL query occurs.

In addition, if you are not using a transaction you will need to call flush before disposing the session.


Thanks
 
Maya sekar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhavi,

Thank you for the response. You were right. Flushing and committing fixed the issue. The deletion is now reflected in the database. But only now when I run my code I get a new error...



an error i was not getting previously. Can you help me?

Thank you so much.
Have a nice day.
 
Madhavi Subramaniam
Ranch Hand
Posts: 33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maya,

Can you try like this

Query query2=session.createQuery("delete from BeaconDetailBean where storeId=:storeID");
query2.setBigInteger("storeID",storeId);
int rowcount=query2.executeUpdate();


Thanks
 
Maya sekar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhavi,

When I used the query as you mentioned...
"delete from table_name where column_name=:paramname"
I get a

error.


thank you
Have a nice day
 
Madhavi Subramaniam
Ranch Hand
Posts: 33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey maya..

That is the common syntax.

BigInteger myBig = new BigInteger(storeId);
Session session = HibernateUtil.getSessionFactory().openSession();
Query query2=session.createQuery("delete from BeaconDetailBean bbean where bbean.storeId="+myBig +"");
int rowcount=query2.executeUpdate();

your code is correct..
Make sure the variable name storeId is there in the class BeaconDetailBean.

and have you set the value of store_id in correct data type.
 
Maya sekar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. My code finally works...
Thank you so much for your help Madhavi..
 
Madhavi Subramaniam
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No thanks maya...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic