-->
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.  [ 5 posts ] 
Author Message
 Post subject: DELETE FROM table WHERE id IN (?) in HSQL
PostPosted: Thu Feb 12, 2004 7:07 pm 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
Hi All.

I am running Hibernate 1.2 in jboss-3.2.2 with a postgresql 7.2.1-2

Currently all my queries use named properties ie.

Code:
Query q = session.createQuery(queryText);
q.setParameterList(name,value);
and/or
q.setString(name, value);
etc...


--
What I would like is a DELETE FROM
Ideally I would like to do something like:
Code:
q.delete();
or
session.delete(q);

--

I also like to have a generic DOA interface to queries which this allows me to build.
I like this approach much better to the JDBC (?) for params IMHO.

My problem is that I have a list of 22 records with an id in common that I want to delete from one table using the following.
Code:
ie DELETE FROM table WHERE id = ?;


Though the query is slow (3 sec) and in the logs hibernate runs:
Code:
DEBUG [cirrus.hibernate.impl.SessionImpl] delete: FROM table IN class com.test.Table WHERE id = 74
and then for each matched id:
delete from id where id = ? and foreignKeyId = ?


For future queries I would also like to be able to pass lists, String, Longs etc as I can in an hibernate Query type shown above.

The main reason this has come up is that I was returning a HSQL query then passing all the results to session.delete(); inside one transaction.
This worked as fast as a session.delete(String query) though It still seemed slow and hibernate wanted to delete things one at a time.

I tried using a PreparedStatement which was awesomely fast for the deletes but I would rather just use HSQL with named parameters if I can.

So maybe I am asking too much but I would like to use HSQL with named params for everything and either get hibernate to issue the delete as one SQL call or convert a populated and ready to execute Query Object to what hibernate would issue the data base so I can run it as a PreparedStatement.

Thanks in advance.
Ian...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 7:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hibernate is not really suited for mass deletes. After all it has to load the objects first to take things as cascades, etc. into account.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 4:17 am 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
OK Thank you, is it possible to start with a named param query and convert:
Code:
Query q = session.createQuery(queryText);
q.setParameterList(name,value);
and/or
q.setString(name, value);
etc...

to a ready to run PreparedStatement or a SQL string I can use to create a PreparedStatement ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, thats not possible. Bulk deletes are a feature considered for 2.2. however.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 9:30 am 
Newbie

Joined: Tue Feb 10, 2004 9:26 am
Posts: 12
I will hack a workaround for now and look forward to 2.2.
Thank you very much. : )
Ian...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.