Hello,
I'm using Hiberate version 3.3.1 and trying to write a very simple one to many mapping where deletes are performed efficiently. I've got a number of mappings and am happy with Hibernate for inserting/selecting/etc., but I'm looking at how to efficiently delete relationship, and failing to find a good example.
I have two objects, Application and Event. Application has a set of Events (so a one to many relationship).
Here are the relevant mappings:
<hibernate-mapping>
<class name="Application">
<cache usage="read-write"/>
<id name="id" column="applicationId">
<generator class="native"/>
</id>
<set name="events" inverse="true"
cascade="all,delete-orphan" lazy="extra">
<key column="applicationId" />
<one-to-many class="Event" />
</set>
</class>
</hibernate>
<hibernate-mapping>
<class name="Event" polymorphism="implicit">
<id name="id" column="eventId">
<generator class="native"/>
</id>
<many-to-one name="application"
column="applicationId"
not-null="true"/>
</class>
</hibernate>
This relationship works perfectly correct for adding/updating - I can add events to the set in Application, call session.persist(application) and everything is updated as I would expect. However the delete is very inefficient. If I delete an application then hibernate deletes each event separately;
Hiberate: delete from Event where eventId=?
etc.
What I'd like it to do is:
delete from Event where applicationId=?
This seems a fairly basic requirement so I apologise for clearly missing the documentation, but could someone tell me how it's done?
Thanks,
J
|