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

LifecycleListener invocation order inconsistent when listeners are added to the EntityManagerFactory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.2.3, 2.0.1, 2.1.1, 2.2.2, 2.3.0
    • None
    • kernel
    • Patch Available

    Description

      The EntityManagerFactory contains the method addLifecycleListener(). While the EntityManagerFactory never invokes these listeners itself, it does add them to any EntityManagers created by the factory.

      Unfortunately, the EntityManagerFactory stores the listeners added to the factory in a java.util.HashMap. As a result, the order that the listeners were added is lost. If there is a dependency in the listener order then it is impossible to guarantee the order in which listeners are invoked. As an example, if listener one modifies an object in the beforePersist() handler, and listener two writes audit records describing changes in a separate beforePersist() handler, then it is important to be to control the order in which the listeners are executed.

      The attached patch and unit test replaces the HashMap inside of AbstractBrokerFactory with a LinkedHashMap so that listeners are invoked in predictable order.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jeffoh Jeff Oh
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: