I got the following warning:Sep 15, 2009 5:52:48 PM com.avaje.ebean.server.persist.DefaultPersister saveAssocManyIntersectionWARNING: Save cascade on ManyToMany [purposes]. The collection [class java.util.HashSet]was not a BeanCollection. The additions and removals can not be determined and *NO* inserts or deletes to the intersection table occured.
I understand the problem - the owning instance is new so the set is of course a HashSet and not a BeanCollection.So what is the solution to this problem?1) I need to save the owning object first and load it again so as I now have a BeanCollection2) Cascading could probably assume that it should insert all the objects in the set if the owning object is new?
Perhaps there is a simple elegant solution?
Hmmm,
Yes, 2) is probably an option...
The other option is to just insert if it's not a BeanCollection and not bother checking the parent.
If it is not a BeanCollection then it's parent is new (not from query) or the application code set it... so either way it is probably reasonable to consider the beans it contains as inserts.
Aka, the original thinking/design could be considered too conservative.
This change has been made in HEAD.
So if the parent bean is new or the collection is 'vanilla' then all the entries are considered additions and insert into the intersection table.