Orphan Removal on model

172 views
Skip to first unread message

Gonto

unread,
Jan 26, 2012, 1:55:46 PM1/26/12
to play-framework
Hi

I have a relation of OneToMany that I don't want it to be
bidirectional.

The relation is:

@MinSize(1)
@Required
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,
orphanRemoval= true)
@JoinTable( name = "ProductItemForProduct",
joinColumns = @JoinColumn(name = "productId"),
inverseJoinColumns = @JoinColumn(name =
"productItemId"),
uniqueConstraints = @UniqueConstraint(name =
"uq_productItemPerProduct", columnNames = {
"productId", "productItemId"}))
public Set<ProductItem> items = Sets.newHashSet();


The problem is that I'm getting an error each time that I edit the
element:
"org.hibernate.HibernateException: A collection with cascade="all-
delete-orphan" was no longer referenced by the owning entity instance"


So I started to debug code, and the problem is that Play JPA plugin
when does the binding of a OneToMany relation, it creates a new
HashSet and then it fills it with the elements ans assign it to the
parent object. That's precisely the problem.

If we use orphanRemoval, Hibernate needs the Collection NOT to be set
again, and to be modified the one that exists. You can either clear it
and add all of the elements again. If I don't set the orphanRemoval,
the ProductItem table increases exponentially.

Is there any solution to this?

Thanks

Gonto

unread,
Jan 30, 2012, 2:42:03 AM1/30/12
to play-framework
I think this is a bug, can anyone confirm this?

If it's, then we'll be creating a pull request for the fix. The
collection shouldn't be created in my opinion.

Regards

Conrado

unread,
Apr 21, 2012, 10:06:29 PM4/21/12
to play-fr...@googlegroups.com
I just had the same problem and reached the same conclusion.

It would be better if Play preserves the original collection instance.
Reply all
Reply to author
Forward
0 new messages