Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL add works, delete doesnt

 
David Silkin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive been able to add records to db, however when I try to delete, nothing happens despite executeUpdate() returning the correct number of rows, indicating that the query works lol

i dont think looking at the snippet is necessary but here it is anyway...


Ive searched the forum for similar problems but cant find it. I can post the hbm files etc in reply, I will continue to work on it and if I find the answer, Ill post it. Thanks in advance for any help
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* could it perhaps be that the transaction is not committed ?

* do you see the hibernate sql pass on the screen if you have <property name="hibernate.show.sql" value="true"> ?

if so try to execute that sql manually to see if that works.

grtz
mark

 
David Silkin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark, heres the hibernate sql being output to console:

Hibernate: delete from user where username=?

Rows affected 3 - this is just an extra out statement for me to see if any rows were returned. I will look into the transaction being committed as well as the manual SQL option. Thanks for reply!
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you close the session and see if it works?
 
David Silkin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the helpful replies so far. Mark, I did as you suggested and committed the transaction, and I also closed session as you advised, Sridhar. This is what I got:



oh dear. I think that sorta changes the scope of this topic, I dont want to disobey the rules. At least I've moved a step forward thanks to you guys. Any advice before I move along is welcome, your help has been appreciated, this site is great
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

You should have sometime like this.



Hope this help you.
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, like Vishal Pandya says, you've got to have a transaction.
 
David Silkin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I will look at that, I saw some problems in the code. I wasnt passing objects to hibernate to persist. More reading is required. Thanks
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the attitude.
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to bring one point here is why do you need to close the transaction, to my understanding hibernate automatically makes the transaction of the method by default. so if the method ends it should automatically commit until something goes wrong.

Thanks,
Rahul
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Citation Needed]
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Juneja wrote:Just to bring one point here is why do you need to close the transaction, to my understanding hibernate automatically makes the transaction of the method by default. so if the method ends it should automatically commit until something goes wrong.

Thanks,
Rahul


You wouldnt need to, if its a CMT.
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sridhar Santhanakrishnan wrote:
Rahul Juneja wrote:Just to bring one point here is why do you need to close the transaction, to my understanding hibernate automatically makes the transaction of the method by default. so if the method ends it should automatically commit until something goes wrong.

Thanks,
Rahul


You wouldnt need to, if its a CMT.


I agree.

Thanks,
Rahul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic