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.  [ 3 posts ] 
Author Message
 Post subject: One Shot Delete with an unmanaged list
PostPosted: Mon Jul 14, 2008 11:50 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 10:51 pm
Posts: 29
Location: sydney australia
I'm trying to use the "one shot delete" feature, but I'm gathering it's only available if you're using it with a collection which is a field of a persistent entity - what I want to do is have hibernate manage the deletes from the result of a query.

essentially i want to perform a criteria delete, under hibernates session/transaction management. the "one shot delete" via list.clear method might not be the best idea, so other suggestions welcome.

thanks.


Hibernate version: 3.2.3 ga

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="com.jdo.MyClass">
   
      <id name="id" column="pk">
         <generator class="native"/>
      </id>
      
      <many-to-one name="abc" class="com.jdo.MyClass2" lazy="false" not-null="true"/>
      <many-to-one name="def" class="com.jdo.MyClass3" lazy="false"/>

      <property name="ghi" not-null="true"/>
      <property name="jkl"/>
      <property name="mno" not-null="true"/>
      <property name="pqr" not-null="true"/>
      
      <property name="stu" not-null="true" type="date"/>
      <property name="xyz" not-null="true"/>
      
   </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Query qry = sFac.getSession().createQuery("FROM " + MyClass.class.getName() + " AS t WHERE t.abc=:abc AND t.xyz=:xyz");
qry.setEntity("abc", abc);
qry.setBoolean("xyz", xyz);

List list = qry.list();
list.clear();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 11:58 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 10:51 pm
Posts: 29
Location: sydney australia
i guess i'm better off doing the following eh?

Code:
Query qry = sFac.getSession().createQuery("DELETE " + MyClass.class.getName() + " AS t WHERE t.abc=:abc AND t.xyz=:xyz");
qry.setEntity("abc", abc);
qry.setBoolean("xyz", xyz);
qry.executeUpdate();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 9:44 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
This looks a little better. :) I'd go with it.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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