Gonto
unread,Jan 26, 2012, 1:55:46 PM1/26/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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