-->
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.  [ 1 post ] 
Author Message
 Post subject: Batch delete fails and individual delete statements issued
PostPosted: Mon Feb 02, 2009 6:46 pm 
Newbie

Joined: Tue Apr 25, 2006 1:17 pm
Posts: 19
Hibernate version: 3.2

Problem/Question: How can I issue bulk deletes so that all entries in the associate link table as well as the row in the target table is deleted?
I want to delete all entries in the EventPersonLink table that correspond to a particular Event as well as that specific Event.

My database mapping:
Person --- EventPersonLink --- Event
where EventPersonLink table contains an ID to Person as well as an ID into the Event table.

Mapping documents:
<hibernate-mapping>
<class name="Person" table="Person" dynamic-update="true">

<id name="id" type="int">
<column name="ID"/>
<generator class="identity"/>
</id>
<property name="name" type="string">
<column name="Name" length="128" not-null="true"/>
</property>

<set name="events" cascade="save-update" table="EventPersonLink">
<!--<cache usage="read-write"/>-->
<key>
<column name="PersonID" not-null="true">
<comment></comment>
</column>
</key>
<many-to-many entity-name="Event">
<column name="EventID" not-null="true">
<comment></comment>
</column>
</many-to-many>
</set>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="Event" table="Event" dynamic-update="true">
<id name="id" type="int">
<column name="ID"/>
<generator class="identity"/>
</id>

<property name="name" type="string">
<column name="Name" length="128" not-null="true"/>
</property>

<property name="active" type="byte">
<column name="ActiveEvent" not-null="true"/>
</property>

<set name="persons" inverse="true" cascade="all" table="EventPersonLink">
<key>
<column name="EventID" not-null="true"/>
</key>
<many-to-many entity-name="Person">
<column name="PersonID" not-null="true"/>
</many-to-many>
</set>
</class>
<hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Event event = session.get(eventId, Event.class);
event.removeAllPersons();
session.delete(event);

code inside removeAllPersons:
for (Object pObj : this.persons)
{
Person person = (Person) pObj;
person.getEvents().remove(this);
}

this. persons.clear();

What I see:
The above style of delete invokes individual SQL delete statements for each person associated with the event and I would like some help on how to issue a batch delete so that only one SQL delete statement is issued for all rows in the EventPersonLink table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.