-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Are SQLQuery actions executed outside context of Session?
PostPosted: Wed Jan 16, 2008 2:50 pm 
Newbie

Joined: Wed Sep 19, 2007 1:54 pm
Posts: 5
Location: Houston TX
I need to add a simple bulk delete to an existing Hibernate-enabled app.

If I use SQLQueryImpl.executeUpdate() to do this, I assume that it is completely out of the context of an existing session, and has no effect on an existing session.

Is that correct?

Assuming auto-commit is on in my DB, I should see the DELETE committed immediately, correct?

Thanks,
Wes

P. S. If there's some "cool" Hibernate way to delete multiple records with one delete statement via the API, I couldn't find it. If such a method exists, please enlighten me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 7:35 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
As fas as I know, SQLQueryImpl won't let you execute updates or deletes of mapped entities.
For those, an HQL like "delete from MyClass" will do.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 20, 2008 6:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use HQL batch deletes as shown.


that said native SQL queries also supports doing deletes/updates if you want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 20, 2008 6:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
....but do remeber if your sesssion has objects that you delete/modify with these bulk QL statements will be out of sync and cascading will not be applied..hence the best thing is to do this as the first thing when using the session before you load anything.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.