-->
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.  [ 4 posts ] 
Author Message
 Post subject: @OneToMany and Cascade Delete problem
PostPosted: Tue Dec 26, 2006 4:27 am 
Newbie

Joined: Tue Dec 26, 2006 4:19 am
Posts: 2
Hi All,

here is a brief description of the problem I'm facing -

A Product can have many ProductAttribute.

class Product {
@OneToMany(targetEntity = ProductAttribute.class, fetch =
FetchType.EAGER, cascade = {CascadeType.ALL})
@JoinColumn(name = "Product_ID")

public Set<ProductAttribute> getProductAttributes() {
return productAttributes;
}
}


Now when i delete the Product, its setting the PRODUCT_ID in the PRODUCT_ATTRIBUTES table to NULL instead of cascading the delete to the ProductAttribute. I want all ProductAttribute to be deleted when the associated Product is deleted

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 26, 2006 8:03 am 
Newbie

Joined: Tue Dec 26, 2006 4:19 am
Posts: 2
specifying updatable=false on the joincolumn fixed my problem.
Now off to figuring out how to prevent the (n+1) sqls that is being fired to perform cascade delete


Top
 Profile  
 
 Post subject: this was helpful
PostPosted: Tue Dec 26, 2006 4:46 pm 
Newbie

Joined: Tue Dec 26, 2006 4:13 pm
Posts: 1
But I had to figure out that in XML config I need to set the attribute for key
Code:
<key update="false">...</key>
. I suppose this corresponds to teh JoinColumn annotation.

Still I wonder about the number of placed hibernate gets informed that an attribute key-field is not-null and also part of the PK - and still attempts to perform
Code:
update ... set key_field=null ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 11:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use cascade DELETE_ORPHAN (check the doc)

_________________
Emmanuel


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

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.