persistence@glassfish.java.net

RE: [Issue 914] Bidirectional ManyToMany broken

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 10 Aug 2006 11:33:13 -0400

Hello Matt,
    There appears to be an issue with cascade delete and ManyToManys. We are not determining the delete order correctly and thanks for filing issue 915. The user should not be required to maintain the relational table at all. If you were to remove the Patients from the Doctor's ( and visa versa )before calling remove on the Patient (or Doctor) then the JoinTable would be updated automatically for you.

    With the issue you filed for 914 however, the JoinTable is not being updated because both sides of the ManyToMany bi-directional are not being set, as required by the Specification.
--Gordon

-----Original Message-----
From: Matt Powell [mailto:matt_tricks_at_hotmail.com]
Sent: Thursday, August 10, 2006 11:16 AM
To: gyorke_at_dev.java.net
Subject: Re: [Issue 914] Bidirectional ManyToMany broken


Hi,

What about for removal? Is the best way to perform an QL delete on the
JoinTable? Will that cause any referential problems in the persistence
context?

Why is the cascade option allowed at all on a ManyToMany definition if it
will never do anything?

Thanks for your time.

Matt

----- Original Message -----
From: <gyorke_at_dev.java.net>
To: <matt_tricks_at_dev.java.net>
Sent: Thursday, August 10, 2006 9:38 PM
Subject: [Issue 914] Bidirectional ManyToMany broken


> https://glassfish.dev.java.net/issues/show_bug.cgi?id=914
>
>
>
> User gyorke changed the following:
>
> What |Old value |New value
> ================================================================================
> Status|NEW |RESOLVED
> --------------------------------------------------------------------------------
> Resolution| |INVALID
> --------------------------------------------------------------------------------
>
>
>
>
> ------- Additional comments from gyorke_at_dev.java.net Thu Aug 10 13:38:06
> +0000 2006 -------
> The specification requires that users maintain their own relationship
> integrity.
> The addDoctor() method should be as folows:
> public void addDoctor(Patient patient, Doctor doctor) {
> // a find() should be performed instead of the merge.
> // the merge will overwrite the contents of the PC version with the
> // provided user version
> // merge should only be used if the desire is to take advantage of
> // optimistic locking and the patient and doctor are serialized
> // from client.
> Patient p = em.merge(patient); // get the em context version of
> patient
> Doctor d = em.merge(doctor); // get the em context version of
> doctor
> p.getDoctors().add(d);
> d.getPatients().add(p); // it is important to set both
> relationships as
> per spec
> }
>
>
>