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();