Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2199

Constraint violation exception when removing relationship using (orphanRemoval = true)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0, 2.1.0, 2.2.0, 2.3.0
    • 2.0.2, 2.1.2, 2.2.1, 2.3.0
    • jdbc
    • None

    Description

      The problem occurs with the following relationships between classes:

      Parent ->* Child ->* GrandChild. Class Parent has a collection of Childs.
      Class Child has a collection of GrandChilds.
      Each one-to-many relationship is annotated like this: @OneToMany(cascade = CascadeType.
      ALL, orphanRemoval = true, ...). I.e. we use orphan removal and remove operations cascade from parents to children and grandchildren.

      When we do the following a DB constraint violation occurs:
      1) Start a transaction
      2) Load a Parent instance from the database
      3) Navigate to a Child and modify it
      4) Cut the relationship between Child and GrandChild
      5) Cut the relationship between Parent and Child
      6) Commit the transaction

      Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: DELETE on table 'JPAORPHAN_CHILD' caused a violation of foreign key constraint 'SQL120320110237861' for key (11). The statement has been rolled back.

      {prepstmnt 1074806800 DELETE FROM APP.JPAORPHAN_CHILD WHERE ID = ? [params=(int) 11]}

      [code=20000, state=23503]

      Attachments

        Activity

          People

            allee8285 Albert Lee
            allee8285 Albert Lee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: