Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-2349

Cayenne cache issue: 'SelectQuery' with prefetches loses relationships (null)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.0.B1
    • Fix Version/s: 4.0.B2, 4.1.M1
    • Component/s: Core Library
    • Labels:
      None
    • Environment:
      JCacheModule, ehcache.

      Description

      I have faced with the problem when SelectQuery returns wrong query result: returned object lost some of the relationships - they are null.

      I have used prefetches (to load several number of objects in one go) and shared cache (to put query result to cache). I have found an use case where it always reproduces, see my test:

      class CayenneJCacheTest {
      
          def cayenneRuntime
      
          @Test
          void test() {
              cayenneRuntime = new ServerRuntime("cayenne-project.xml", new JCacheModule())
             //select single artist with limited prefetch graph
              selectFew()
             //do the same query but with additional prefetches
              List<Artist> artists =  selectMore()
             // all actor's paintings has a gallery but it is lost from query result - test failed
              assertNotNull(artists[0].paintings[0].gallery)
          }
      
      
          List<Artist> selectFew() {
              //prefetch artist.paintings only, do not prefetch   artist.paintings.gallery
              ObjectSelect.query(CourseClass)
                      .where(Artist.ID.eq('1001'))
                      .prefetch(Artist.PAINTINGS.joint())
                      .cacheStrategy(QueryCacheStrategy.SHARED_CACHE)
                      .cacheGroup(Artist.class.simpleName)
                      .select(cayenneRuntime.newContext())
          }
          
           List<Artist> selectFew() {
              //prefetch all related objects
              ObjectSelect.query(CourseClass)
                      .where(Artist.ID.eq('1001'))
                      .prefetch(Artist.PAINTINGS.joint())
                      .prefetch(Artist.PAINTINGS.dot(Painting.GALLERY).joint())
                      .cacheStrategy(QueryCacheStrategy.SHARED_CACHE)
                      .cacheGroup(Artist.class.simpleName)
                      .select(cayenneRuntime.newContext())
          }
          
      }
      

        Attachments

          Activity

            People

            • Assignee:
              ntimofeev Nikita Timofeev
              Reporter:
              Artyom Artyom Kravchenko
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: