-->
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: session.delete(query)
PostPosted: Thu Jun 17, 2004 1:46 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
Hi,

I would like to do a delete several objects with a query like that
"from Device d where d.id in (:idlist)".

With a query, I will use query.setParameterList("idlist", ids) to bind the named parameter.
How can I do that with the session.delete() ?

Christophe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 1:55 pm 
Newbie

Joined: Wed Jun 16, 2004 5:21 pm
Posts: 3
Location: Portland, OR, USA
Looks like you are having fun learning too! Here's what I did...

I did a query.list() to retrieve a list of all objects that satisfy the query, then call session.delete(Object) on each of them. If you're not familiar with query.list, you can also use either session.find() for a full list of objects all in memory at the same time, or session.iterate() to bring them back one by one... at the expense of executing SQL for each row.

Code:
   try {
      session = hSessFact.openSession();
   }
   catch(HibernateException e) {
      logger.error("Could not create Hibernate Session.", e);
      throw e;
   }
   try {
      Query query = session.getNamedQuery("ConxxxxRequest_by_job_id");
      query.setString("JOBID", jobName);
      tx = session.beginTransaction();
      jobList = query.list();
      ListIterator li = jobList.listIterator();
      while(li.hasNext()) {
         ConxxxxRequest request = (ConxxxxRequest)li.next();
         session.delete(request);
      }
      tx.commit();
   }
   catch(Exception e) {
      if(tx != null) {
         tx.rollback();
      }
      logger.error("Hibernate processing error.", e);
   }
   finally {
      session.close();
   }

_________________
DeVon


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.