-
1. Re: deleting entities from a Collection
aberezin Sep 7, 2006 6:03 PM (in response to aberezin)I think I have part of the answer: See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=56357
The short answer seem to be that in a bidirectional OneToMany, you must explicitly delete the entity after removing it from the collection. However, in that post, Bill Burke seems to indicate that a "non-inverse", which I assume is a unidirectional relationship, would automatically delete the entity when it is removed from the collection. -
2. Re: deleting entities from a Collection
a_titov82 Sep 9, 2006 6:39 AM (in response to aberezin)And is there any way to remove related object without explicitly calling EntityManager.remove and EntityManager.find? I have no EntityManager instance in remote client application... Maybe I can just remove related entity from collection in base object and then save base object somehow?
-
3. Re: deleting entities from a Collection
laszlo.fogas Sep 10, 2006 10:02 AM (in response to aberezin)define a hibernate specific annotation, because this kind of deleting ejb3 spec does not support. In hibernate it's delete_orphan cascade type..
use@OneToMany(fetch = FetchType.LAZY, mappedBy = "felhasznalok") @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) public Set<Kedvencek> getKedvenceks() { return this.kedvenceks; }
-
4. Re: deleting entities from a Collection
aberezin Sep 10, 2006 11:33 AM (in response to aberezin)Thanks for the tip.
I could seem to get CascadeType.DELETE_ORPHAN to work in 4.04ga with a Set (didnt try with a List). I saw a bug related to this, http://opensource.atlassian.com/projects/hibernate/browse/EJB-53 but it appears fixed long ago.
I made a little test case that persists the Order with one OrderItem. I then call order.getOrderItems().clear() and then call (thru the sessionbean) em.merge(order) and even do an explicit flush(). The underlying row for the OrderItem is not deleted.
This whole thing is not a big deal since I can explicitly delete the child objects no longer in the Set. I was just curious as to how to do it automatically. -
5. Re: deleting entities from a Collection
aberezin Sep 10, 2006 11:35 AM (in response to aberezin)Oops, I meant to say that I could NOT get the DELETE_ORPHAN to work.