aspose file tools*
The moose likes Object Relational Mapping and the fly likes HQL add works, delete doesnt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL add works, delete doesnt" Watch "HQL add works, delete doesnt" New topic
Author

HQL add works, delete doesnt

David Silkin
Greenhorn

Joined: Jan 19, 2009
Posts: 6
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

Joined: Mar 02, 2004
Posts: 159

* 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


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
David Silkin
Greenhorn

Joined: Jan 19, 2009
Posts: 6
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

Joined: Mar 20, 2007
Posts: 317
Why don't you close the session and see if it works?
David Silkin
Greenhorn

Joined: Jan 19, 2009
Posts: 6
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

Joined: Aug 16, 2007
Posts: 1374
David,

You should have sometime like this.



Hope this help you.
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Yes, like Vishal Pandya says, you've got to have a transaction.
David Silkin
Greenhorn

Joined: Jan 19, 2009
Posts: 6
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

Joined: Aug 16, 2007
Posts: 1374
That's the attitude.
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
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


Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
[Citation Needed]
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
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

Joined: Aug 03, 2002
Posts: 425
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HQL add works, delete doesnt