-->
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: delet list of keys
PostPosted: Mon Jun 16, 2008 9:28 am 
Newbie

Joined: Mon Jun 16, 2008 9:13 am
Posts: 2
Hello

I have a query that returns a list of primary keys

Code:
List<Keys> keys = executeQuery(query);


and I need to delete the list.

question: is there any way to delete the list at once?

example

Code:
delete(keys);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 10:02 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

What is the query that you pass to get the List of keys??

If you are deleting based on PK:
you have to option of deleting with session.delete() or use HQL through manual iteration..


If you are deleting based on some field:
1) use HQL to delete the row giving your field on the where clause.
String hqlDelete = "delete Customer c where c.name = :oldName";
int deletedEntities = s.createQuery( hqlDelete )
.setString( "oldName", oldName )
.executeUpdate();

2) session.delete("select customer FROM Customer as customer where customerType = 'XXXX'");

If you are using Spring Hibernate Template:
1) HibernateTemplate.deleteAll(Collection)
2) getHibernateTemplate().bulkUpdate(”delete from Customer where customerType = ?”, type);

Hope this helps...If not elaborate:-)

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 10:18 am 
Newbie

Joined: Mon Jun 16, 2008 9:13 am
Posts: 2
ramnath wrote:

If you are deleting based on some field:
1) use HQL to delete the row giving your field on the where clause.
String hqlDelete = "delete Customer c where c.name = :oldName";
int deletedEntities = s.createQuery( hqlDelete )
.setString( "oldName", oldName )
.executeUpdate();






I need something like this, but instead of oldName I need to put a list


there is some way?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 11:21 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Hi,
you can use this; I am not sure if you key is a composite key.

Try this

String hqlDelete = "delete Item i where i.id = :ids";
int deletedEntities = session.createQuery( hqlDelete ).setParameterList("ids", keys).executeUpdate();

where keys is a list of your keys.

What is the type of your composite key?

Hope this help

_________________
Alan Mehio
London
UK


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.