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

With L2 Cache turned ON newly persisted entity on inverse side of relation doesn't have FK populated on 'find'/'query'



    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.2, 2.3.0
    • Fix Version/s: None
    • Component/s: datacache, jpa
    • Labels:
    • Environment:
      apache karaf 2.3.0, openjpa 2.2.2


      With l2 cache turned on (by setting "openjpa.DataCache" property to "true" in persistence.xml) we observed following behavior:

      Lets say we have model Person <-> Address(LAZY, owner). We create a new instance of Person and Address. Since Person is non-owing side of relation, we set Person instance in Address but don't set Address instance in Person. We then persist both Person and Address instance. Later when we query Person entity by using EntityManager.find method the returned instance of Person doesn't have Address field set. This field doesn't get set even if we query Address entity.

      It appears that Person entity that was created when we persisted gets cached and it doesn't get refreshed when we query for that instance.

      I have looked at defect https://issues.apache.org/jira/browse/OPENJPA-2285 and applied that fix to open jpa 2.2.2 but I still see the same behavior. I did some debugging and found that PCDataImpl.isLoaded method always returns true for the 'address' field and hence it looks up in its internal "_data" object array for value, which has null for 'address' field. In effect the check of the loadedFieldsAfter and loadedFieldsBefore introduced in OPENJPA-2285 doesn't trigger and cache is never updated.

      I have verified that this is indeed a cache problem by evicting the "Person" class from datacache (using EntityManagerFactory.getCache().evict(Person.class) method) and making sure that further queries for that Person instance returns address when we try to access that field.


        1. Address.java
          1 kB
          Atul Kshirsagar
        2. persistence.xml
          1 kB
          Atul Kshirsagar
        3. Person.java
          1 kB
          Atul Kshirsagar
        4. TestL2CacheLazyLoading.java
          3 kB
          Atul Kshirsagar



            • Assignee:
              akshirsa Atul Kshirsagar
            • Votes:
              1 Vote for this issue
              3 Start watching this issue


              • Created: