-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA Cascade ALL update collection elements
PostPosted: Fri Apr 16, 2010 5:11 am 
Newbie

Joined: Fri Apr 16, 2010 4:35 am
Posts: 1
Hi, can anyone help me with this problem?

I have two entities (products and attributes of the product) mapped with annotations this way:

ProductVO --> 1-N --> AttribVO

ProductVO
----------------
@OneToMany(fetch=FetchType.EAGER,mappedBy="product",cascade=CascadeType.ALL)
@OrderBy("order ASC")
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<AttribVO> attribs;


AttribVO
----------------

@ManyToOne
@JoinColumn(name="LPRODUCTID")
private ProductVO product;

I have two attributes "a" and "b" for the product. If I set a new list of attributes (only with a "c" attribute) in product and update it, attributes "a" and "b" are not deleted and attrib "c" is added to the list of attributes:

Product p = findProduct();
//I have 2 attributes here
p.getAttribs();
List<AttribVO> aList = new ArrayList<AttribVO>();
aList.add(new AttribVO("c"));
//Only attribute c here
p.setAttribs(aList);
updateProduct(p);


Can I update the product attributes list and delete products "a" and "b" with this mapping or i can't make this and i have to do a "pre-delete" of the attributes??

Thanks for your help.

Best regards.


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

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.