-->
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.  [ 2 posts ] 
Author Message
 Post subject: Deleting Multiple Entities at once
PostPosted: Wed Apr 06, 2011 11:07 am 
Newbie

Joined: Wed Apr 06, 2011 11:03 am
Posts: 2
I am new to Hibernate, cannot find the simple documentation of how to remove multiple entities at once. I see I can use entityManager.remove(Object obj), but if I have a collection (ie: I can query a list) I would rather not loop through and make a delete call on each individual id.

I can use native sql as it is a simple call, but is that advised, meaning will that make the Hibernate interface out of sync. I am just looking for the best way to do a simple mass delete by id to a table.

Thank you so much, sorry for the simple question, but google and api don't seem to be helping.

msj121


Top
 Profile  
 
 Post subject: Re: Deleting Multiple Entities at once
PostPosted: Fri Apr 08, 2011 10:34 am 
Newbie

Joined: Wed Apr 06, 2011 11:03 am
Posts: 2
I found on the iirc the following, "odin_" helped me out:

Item item = session.get(Item.class, Integer.valueOf(id));
Query q = session.createQuery("DELETE FROM " + com.msj.entities.CategoryMap.class.getName() + " WHERE item=?");
q.setEntity(0, item);
q.executeUpdate();


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