• 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Delete Query problem: Failure to Commit HQL Delete Transaction

 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my class for delete


after run this class it shows out as


it says one row is deleted
but when i run this query it shows both rows


Out put is here


where is the error?
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't commit so your transaction did a rollback when you closed the session.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where is the Transaction. ?
there is no any transaction.
can't we create a session without transaction?
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
session.getTransaction() gives you the transaction. No, you cannot do any database operation outside a transaction (apart from some nontransactional "databases"). Even in autocommit-mode there is a transaction inside the database.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oho.
then you mean this is wrong
http://www.roseindia.net/hibernate/firstexample.shtml

check is it wrong or not?
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's wrong. If data isn't commited it must be wrong. I don't know MySQL that much but wasn't there a storage engine that didn't support transactions and another one that did? If you used the one that supported transactions the sample from roseindia cannot work. (Despite using autocommit-mode I think.)
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed you need to have a transaction to update the database, but it does not have to explicitly coded. You can configure to have Application Server manage the transaction on its own in some cases. (CMT i think.)

Dont know if it helps but how about trying a session.flush() before you close the session?
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but this view query is working.


there is no any transaction in this code.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what you mean by "it's working"...
Not using a transaction will not get you an exception - in that sense it's working. The problem is that whatever you do, it's cancelled as soon as you close the session (unless you have a non-transactional DB, as Christian mentioned, or you're working in the autocommit mode). Although, to be precise, according to this article, it's not 100% sure.
It seems that's exactly what's happening in your DeleteQuery,
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your view query is working because it is just selecting something from a table....

and your delete is not working because you have changed the table and you didnt say commit.

One more question how are you building your session factory is it being managed by an App Server, if yes then call session.flush() as mentioned above...

If no check whether you db is transaction or non transactional, i feel its transactional so get the Transaction from session and do a commit.

Hope this helps.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using NEtbeans 6.8 IDE
Server is GlassFish which comes with Built in with Netbeans
DB is Java DB wich comes with Netbeans
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you showed above is not inside Glassfish! Thats plain old java without any application server, transaction manager or DI voodoo. No commit no database change. If you call flush you make it even worse because Hibernate prints the query and you think everything is okay, but then you don't see the rollback.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic