Kuali Rice Development
  1. Kuali Rice Development
  2. KULRICE-4103

JPA refresh strategy won't work with Orphan Removal

    Details

    • Type: Bug Fix Bug Fix
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: None
    • Fix Version/s: Not version specific
    • Component/s: Development, JPA
    • Labels:
      None
    • Similar issues:
      KULRICE-11075Document JPA testing strategy
      KULRICE-9110Remove old JPA "shim" code (i.e. BusinessObjectDaoProxy) because it won't be needed any longer
      KULRICE-11372Solicit feedback on and refine JPA testing strategy doc
      KULRICE-7029Remove refresh property on ComponentBase
      KULRICE-7870Tooltips are not removed if a timed refresh occurs while they are open
      KULRICE-13166Investigate better option to materialize sub objects in JPA
      KULRICE-13301Refresh in Edit dialogs
      KULRICE-3896KNS Unit Test BOs need to be JPA annotated
      KULRICE-3853JPA - Proof of concept with sequence / identity/ prePersist
      KULRICE-6014JPA Conversion Guide
    • Rice Module:
      KNS

      Description

      Currently, the JPA refresh strategy is to roll our own query based on association metadata, since JPA/Hibernate doesn't have great "refresh" options. However, as discovered by KULRICE-4087, overwriting a collection Hibernate is tracking for orphan removal with some other collection - like the refresh strategy does - make Hibernate angry. And, no, none of us don't like Hibernate when it's angry.

      So, we need a better strategy; and I believe that strategy starts with analysis of where refreshing is used...

        Issue Links

          Activity

          Hide
          James Smith added a comment -

          Added a unit test to the branches/training/jpa_jta_experiment ParentChildTest to illustrate this. The test above has some helpful info...

          Show
          James Smith added a comment - Added a unit test to the branches/training/jpa_jta_experiment ParentChildTest to illustrate this. The test above has some helpful info...
          Hide
          James Smith added a comment -

          So, again: childrenRetrievedDirectly() always worked, even though it reset the collection that had orphan removal. Why was that?

          Well, because evidently, this is kosher:

          p = em.find(Parent.class, firstId+2);
          em.clear();
          p.setChildren(new ArrayList<Child>(childrenFromDb));
          p = em.merge(p);
          em.flush();

          ...specifically, the fact that before the collection is set, p is detached (as well as the list), and then p gets merged back again, forcing the save. That works just fine in my unit tests written specifically to test that.

          Ah...but is it an effective strategy? Basically, in a refresh, we'd have to detach the object for a while, change the lists, and then refresh would have to return the merged copy of the object itself. That seems like a pretty hefty change - I know it'd have a major impact through the KFS code base; I'll ask Travis about KC implications.

          Show
          James Smith added a comment - So, again: childrenRetrievedDirectly() always worked, even though it reset the collection that had orphan removal. Why was that? Well, because evidently, this is kosher: p = em.find(Parent.class, firstId+2); em.clear(); p.setChildren(new ArrayList<Child>(childrenFromDb)); p = em.merge(p); em.flush(); ...specifically, the fact that before the collection is set, p is detached (as well as the list), and then p gets merged back again, forcing the save. That works just fine in my unit tests written specifically to test that. Ah...but is it an effective strategy? Basically, in a refresh, we'd have to detach the object for a while, change the lists, and then refresh would have to return the merged copy of the object itself. That seems like a pretty hefty change - I know it'd have a major impact through the KFS code base; I'll ask Travis about KC implications.
          Hide
          James Smith added a comment -

          And of course, it must be remembered that this is a trade-off: the Hibernate-driven orphan removal versus refreshReference working under old semantics.

          Show
          James Smith added a comment - And of course, it must be remembered that this is a trade-off: the Hibernate-driven orphan removal versus refreshReference working under old semantics.
          Hide
          Travis Schneeberger added a comment -

          "I'll ask Travis about KC implications. "

          Yes that would suck for KC... We use refreshReference all over our application (actions, forms, services, rules) - everywhere.

          Show
          Travis Schneeberger added a comment - "I'll ask Travis about KC implications. " Yes that would suck for KC... We use refreshReference all over our application (actions, forms, services, rules) - everywhere.
          Hide
          James Smith added a comment -

          Thanks Travis! (And I promise: I was in the middle of composing the e-mail...)

          Show
          James Smith added a comment - Thanks Travis! (And I promise: I was in the middle of composing the e-mail...)
          Hide
          Jessica Coltrin (Inactive) added a comment -

          still relevant, but not blockers - downgrading to Major

          Show
          Jessica Coltrin (Inactive) added a comment - still relevant, but not blockers - downgrading to Major
          Hide
          Jessica Coltrin (Inactive) added a comment -

          later phase of JPA conversion is complete. Closing JIRAs from earlier attempts.

          Show
          Jessica Coltrin (Inactive) added a comment - later phase of JPA conversion is complete. Closing JIRAs from earlier attempts.

            People

            • Assignee:
              Unassigned
              Reporter:
              James Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Structure Helper Panel