This week's book giveaway is in the Functional programming forum.
We're giving away four copies of Functional Design and Architecture and have Alexander Granin on-line!
See this thread for details.
Win a copy of Functional Design and Architecture this week in the Functional programming 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Hibernate row deleted msg received but not reflected in DB

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 33
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No thanks maya...
reply
    Bookmark Topic Watch Topic
  • New Topic