aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate:many-to-many: hibernate deletes too much Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate:many-to-many: hibernate deletes too much" Watch "hibernate:many-to-many: hibernate deletes too much" New topic
Author

hibernate:many-to-many: hibernate deletes too much

Matthew Tripp
Greenhorn

Joined: Jul 15, 2009
Posts: 5
So here's the deal,

I have a 3 tables, test, test2, and test_test2_join (the association table between test and test2)
hibernate is doing its thing and when I have objects from test and test2 that are related, it automatically puts a row in the association table. Its great. The problem is when I delete a row.

Here's a junit test that illustrates the problem:


So if I have the following rows in Test


The following rows in Test2




the above test will end up deleting the rows I have marked with asterisks. This is bad. Don't want this. I only want the rows inserted in the junit test to be deleted. What is the very stupid mistake I am making? Any help is appreciated.


Also here is the mapping file, if that is helpful



thanks in advance

trippy


I hate signatures.
Benjamin Winterberg
Ranch Hand

Joined: Sep 19, 2007
Posts: 36
Take a look at how Cascade works in Hibernate. You have marked the relation with cascade = all. This means that when you delete an entity all related entities will be deleted as well.


Hibernate DAOs with Spring | Separation of Concerns | Eclipse Code Templates | more...
Matthew Tripp
Greenhorn

Joined: Jul 15, 2009
Posts: 5
ben win wrote:Take a look at how Cascade works in Hibernate. You have marked the relation with cascade = all. This means that when you delete an entity all related entities will be deleted as well.


Well shux.

perfectly logical and obvious. I am relying too much on tools generating my configuration and too little on actual understanding.

Thank you for the guidance.
 
jQuery in Action, 2nd edition
 
subject: hibernate:many-to-many: hibernate deletes too much