glassfish
  1. glassfish
  2. GLASSFISH-915

ManyToMany cascade remove doesn't seem to work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 9.1pe
    • Fix Version/s: 9.0pe
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      915

      Description

      I'm working on the main branch (V2) build 10.

      With respect to code below, when I remove (eg) a doctor from the DOCTOR table
      where there is an existing relationship between that doctor and a patient (ie.
      there is an entry in the JoinTable) I get a foreign key error. This makes sense
      but I would have thought that the point of the cascade=CascadeType.REMOVE on a
      ManyToMany relationship would be to automatically remove such entries.

      Since the JoinTable is automatically generated and maintained in every other
      way, I'd rather now have to write a query to remove the JoinTable entries
      manually if it's at all possible to avoid.

      Please let me know if I'm barking up the wrong tree and removing the mappings
      manually is what I'll always need to do!

      public class Patient implements Serializable {
      ..
      @ManyToMany(targetEntity=ejb.Doctor.class, cascade=

      {CascadeType.ALL})
      private List doctors;
      ..
      }

      public class Doctor implements Serializable {
      ..
      @ManyToMany(targetEntity=ejb.Patient.class, cascade={CascadeType.ALL}

      )
      private List patients;
      ..
      }

      Thanks!
      Matt

        Activity

        Hide
        mf125085 added a comment -

        this sounds like the same problem as filed in issue 879. Can you check?

        https://glassfish.dev.java.net/issues/show_bug.cgi?id=879

        Show
        mf125085 added a comment - this sounds like the same problem as filed in issue 879. Can you check? https://glassfish.dev.java.net/issues/show_bug.cgi?id=879
        Hide
        gyorke added a comment -

        This is a duplicate of an already filed bug

            • This issue has been marked as a duplicate of 879 ***
        Show
        gyorke added a comment - This is a duplicate of an already filed bug This issue has been marked as a duplicate of 879 ***
        Hide
        matt_tricks added a comment -

        Looks like it probably is the same. Any word on whether it will be implemented?
        The alternatives to a well behaved cascade delete are pretty messy. The only one
        that I can think of that's feasible for performance is to run a delete query on
        the JoinTable. Anything else running from code in the entities would I guess
        require 1 table lookup and M removals.

        Thanks,
        Matt

        Show
        matt_tricks added a comment - Looks like it probably is the same. Any word on whether it will be implemented? The alternatives to a well behaved cascade delete are pretty messy. The only one that I can think of that's feasible for performance is to run a delete query on the JoinTable. Anything else running from code in the entities would I guess require 1 table lookup and M removals. Thanks, Matt

          People

          • Assignee:
            marina vatkina
            Reporter:
            matt_tricks
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: