This content has been marked as final.
Show 4 replies
-
1. Re: deletion of few elements in one to many collection.
waynebaylor Jul 23, 2007 9:58 AM (in response to jdijkmeijer)do you have the @OneToMany(mappedBy) attribute set?
-
2. Re: deletion of few elements in one to many collection.
jdijkmeijer Jul 23, 2007 12:42 PM (in response to jdijkmeijer)the relationship in the parent entity is mapped like:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "subject") public List<Actor> getActors() { return this.actors; }
the child entity has:@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "subjectid", nullable = false) @NotNull public Subject getSubject() { return this.subject; }
-
3. Re: deletion of few elements in one to many collection.
waynebaylor Jul 23, 2007 1:19 PM (in response to jdijkmeijer)so the Actor objects are removed from the set, but not from the DB, correct?
you have CascadeType.ALL set, which would only delete the Actor objects if you deleted the parent Role object. So, yes, if you also want them removed from the DB you'll have to call em.remove(..); within the for loop.
if you're using Hibernate, another option is to set the Hibernate specific Delete_Orphan cascade type. Then you're Actor objects will automatically be deleted from the DB when you remove them from the parent. -
4. Re: deletion of few elements in one to many collection.
jdijkmeijer Jul 24, 2007 9:06 AM (in response to jdijkmeijer)Okay,
That clarifies it A LOT. Thanks!
jeroen.