Hi Dale,
I don't know if you've been watching this thread but Mike Horowitz helped me
solve my problem(s). And the solution to one of the problems (how to delete
all elements from a Collection) was exactly what you suggest in your last
post, namely call clear() on the Set. It works perfectly, thanks for the
help!
I plan on writing up a tutorial for this scenario - ManyToMany implemented
using 2 OneToMany relations to a custom Model Object. I think it must be a
pretty common scenario - a Join table with attributes - and is tricky to get
right in terms of mappings / Annotations, PropertyEditor, etc.
I'll let the list know when it's up.
Cheers,
Bob
DNewfield wrote:
>
> syg6 wrote:
>> 1. Load ObjectA from database (to get existing ObjectB Collection).
>> 2. Use ObjectBManager to get() each ObjectB
>
> Huh? Shouldn't ObjectA contain a collection of ObjectBs? Why do you
> need to to some other source for these objects? When I mentioned
> manipulating the collection contained in ObjectA carefully I was
> explicitly talking about the collection object, not the ObjectBs
> contained within it.
>
>> 3. Use ObjectBManager to remove() each ObjectB
>> 4. Call ObjectAManager.save()
>
> If ObjectA contains a collection that references ObjectBs that have been
> deleted, then your ObjectA is in an invalid state. You shouldn't remove
> an ObjectB from the DB without first removing it from every collection
> it is in.
>
>> objectA.setObjectBs(null) I get a 'A collection with
>> cascade="all-delete-orphan" was no longer referenced by the owning entity
>> instance' error.
>
> Right--that's specifically complaining about the collection, which is
> managed by Hibernate so that it can figure out which entries are no
> longer present so it can detect orphans. Try replacing
> "objectA.setObjectBs(null)" with
>
> if (objectA.getObjectBs() != null) {
> List<ObjectB> asListOfBs = objectA.getObjectBs();
> asListOfBs.clear();
> objectA.setObjectBs(asListOfBs);
> }
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/Many-to-many-collection-problem-tf4670322s2369.html#a13544765
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]