The moose likes Object Relational Mapping and the fly likes Hibernate: Bulk delete on join table? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate: Bulk delete on join table?" Watch "Hibernate: Bulk delete on join table?" New topic
Author

Hibernate: Bulk delete on join table?

Peter Merker
Ranch Hand

Joined: Oct 18, 2003
Posts: 37
Hi,

I have a many-to-many association between classes A and B. Now I want to delete a couple of A-B associations with only ONE delete statement. To further illustrate this: Let's say, we have the following instances and associations:

So far, Hibernate issues two delete statements, one for each collection of B's in each A. Is there a possibility to get this down to just ONE statement, and how?
Peter Merker
Ranch Hand

Joined: Oct 18, 2003
Posts: 37
Is it not possible to reduce the number of delete statements or was my problem description too short? No matter if I used a HQL query or a Criteria, I always ended with two delete statements whereas I'm looking for something which results in this kind of SQL: 'delete from JoinTable where idA in (select id from A where... )' I guess I should add that there are parents and children in the table A. So if I want to delete the associations to B's for a parent, I also want to delete them for it's children.
Peter Merker
Ranch Hand

Joined: Oct 18, 2003
Posts: 37
Hmm. I'm using native SQL now, but this is far from ideal as I'm losing portability this way. This is the code now:

As you can see, Containers and Items are both tuples in the table CONTENT, CONTAINERS2ITEMS is the join table. Contents are structured in nested sets. I didn't write about this before in order not to complicate things unnecessarily.
Anyway, still no one with an idea how to use HQL or a Criteria for this?
[ July 25, 2007: Message edited by: Peter Merker ]
 
IntelliJ Java IDE
 
subject: Hibernate: Bulk delete on join table?
 
Threads others viewed
Boolean Operator
Delete/update associations question
Cascading Delete
Ternary Association
Question on deletes
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture