Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] using Cascade.Remove vs @PrivateOwned

I am reusing the example
 
Product {
 
@OneToMany(mappedBy="product", cascade=CascadeType.ALL)
 List<Characteristic> characteristics = new ArrayList<Characteristics>();
 }

Characteristic{
@OneToOne(cascade=CascadeType.ALL)
Color color ;
 
@ManyToOne
Product product;
 }

I am doing something like this to remove a 'characteristics' and its color.
product.getCharacteristics( ).remove(characteristics);
entityManager.merge(product);
entityManager.remove(characteristics);
 
and I am expecting the corresponding entry of 'characteristics' and color be removed from the db.
For me this works for some of the ids of 'characteristics' and dosent work for higher value of ids. Meaning it sets the foreign_key Product_id to null in characteristics tables but does not remove the relevant row from characteristic table in some cases. And I also checked that this characteristic table entry is not used/referenced in any other table.
 
This is strange , that it works for some ids and dosent work for others. What might be the reason for this behavior. Is my order of steps right ?
 
But as suggested in an earlier post that sometimes the ORM is not complete and the obejct could relate to any other db object.
 
Going by that suggestion I want to use @PrivateOwned so that orphans are removed . Now in my case tables are already existing , Can I just add the @PrivateOwned annotation and expect it to work ? or what will Ineed to do make @PrivateOwned relation to take into effect for that OneToMany relation of characteristics in Product entity. 
 
Appreciate any help/pointers towards this... Thanks!
 
Ash
 

Back to the top