Uploaded image for project: 'Red Hat Process Automation Manager'
  1. Red Hat Process Automation Manager
  2. RHPAM-382

Redundant records are inserted by JPAPlaceholderResolverStrategy

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 7.0.0.GA
    • 6.x.x
    • jBPM Core
    • ER1
      • Unzip 02008390_reproducer04.zip
      • mvn test

    Description

      When you have an entity with a relationship (ManyToOne, but reproducible with OneToOne) to a child entity and persist it as a process variable using JPAPlaceholderResolverStrategy, its child entity is inserted multiple times so it results in multiple redundant records in DB.

      Attached a reproducer 02008390_reproducer04.zip. You can run it with "mvn test".

      Running com.sample.ProcessJPATest
      ...
      Task1 Entry
      A process instance started : pid = 1
      john starts a task : taskId = 1
      Task1 Exit
      Task2 Entry
      mary starts a task : taskId = 2
      Task2 Exit
      java.lang.AssertionError: expected:<1> but was:<8>
      	at org.junit.Assert.fail(Assert.java:88)
      	at org.junit.Assert.failNotEquals(Assert.java:834)
      	at org.junit.Assert.assertEquals(Assert.java:645)
      	at org.junit.Assert.assertEquals(Assert.java:631)
      	at com.sample.ProcessJPATest.testProcess(ProcessJPATest.java:135)
      ...
      

      The reproducer runs with H2 but if I change it to MySQL and check the database, the result is like this.

      mysql> select * from application;
      +----+------+-----------+
      | id | type | person_id |
      +----+------+-----------+
      |  1 | A    |         8 |
      +----+------+-----------+
      1 row in set (0.00 sec)
      
      mysql> select * from person;
      +----+----------+
      | id | fullName |
      +----+----------+
      |  1 | John Doe |
      |  2 | John Doe |
      |  3 | John Doe |
      |  4 | John Doe |
      |  5 | John Doe |
      |  6 | John Doe |
      |  7 | John Doe |
      |  8 | John Doe |
      +----+----------+
      8 rows in set (0.00 sec)
      

      Using a debugger, I observed the Person (child entity) insertion happens every time JPAPlaceholderResolverStrategy.marshal() calls em.merge() for Application (parent entity) during the transaction on Task completion.

      https://github.com/kiegroup/drools/blob/6.5.x/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/marshaller/JPAPlaceholderResolverStrategy.java#L118
      https://github.com/kiegroup/drools/blob/6.5.x/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/marshaller/JPAPlaceholderResolverStrategy.java#L121

      Attachments

        Issue Links

          Activity

            People

              swiderski.maciej Maciej Swiderski (Inactive)
              rhn-support-tkobayas Toshiya Kobayashi
              Marian Macik Marian Macik
              Marian Macik Marian Macik
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: