Uploaded image for project: 'Hibernate ORM'
  1. HHH-11768

foreign key violation with order_inserts=true and cascading persist

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.10, 5.1.7
    • Fix Version/s: 5.2.11, 5.1.12
    • Component/s: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Worked in:
    • Last commented by a user?:
      true
    • Sprint:

      Description

      Inserts statements are executed in wrong order when hibernate.order_inserts=true is set in the configuration, leading to a foreign key violation.

      The problem occurs when both inserting a new entity that references an existing entity and inserting new entity that references another new entity at the same time.

      The problem is hard to explain in words, so please see the attached simple test case that is broken since Hibernate ORM 5.1.

      If "order_inserts" is "false", the second transaction inside the test case creates inserts in this order:

      1. EntityInsertAction[test.orderproblem.MarketResult#1]
      2. EntityInsertAction[test.orderproblem.MarketBidGroup#2]
      3. EntityInsertAction[test.orderproblem.MarketBid#2]
      4. EntityInsertAction[test.orderproblem.MarketResult#2]

      If "order_inserts" is "true", the inserts are wrongly sorted into this order:

      1. EntityInsertAction[test.orderproblem.MarketBid#2]
      2. EntityInsertAction[test.orderproblem.MarketResult#1]
      3. EntityInsertAction[test.orderproblem.MarketResult#2]
      4. EntityInsertAction[test.orderproblem.MarketBidGroup#2]

      Because MarketBid#2 references MarketBidGroup#2, the latter must be saved first, which is not the case with "order_inserts" set to "true", resulting in a ConstraintViolationException.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: