You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Artyom Kravchenko (JIRA)" <ji...@apache.org> on 2017/08/16 07:14:00 UTC

[jira] [Updated] (CAY-2349) Cayenne cache issue: 'SelectQuery' with prefetches loses relationships (null)

     [ https://issues.apache.org/jira/browse/CAY-2349?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Artyom Kravchenko updated CAY-2349:
-----------------------------------
    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:



{code:java}
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())
    }
    
}
{code}


  was:
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:



{code:java}
class CayenneJCacheTest {

    def cayenneRuntime

    @Test
    void test() {
        
        cayenneRuntime = new ServerRuntime("cayenne-project.xml", new JCacheModule())

        selectFew()
        List<CourseClass> classes =  selectMore()
        assertNotNull(classes[0].course)
        assertNotNull(classes[0].course.fieldConfigurationScheme)

    }


    List<CourseClass> selectFew() {

        (ObjectSelect.query(CourseClass)
                .where(ExpressionFactory.inDbExp(CourseClass.ID_PK_COLUMN, '1001'))
                & CourseClass.COLLEGE.eq(college))
                .prefetch(CourseClass.COURSE.joint())
                .cacheStrategy(QueryCacheStrategy.SHARED_CACHE)
                .cacheGroup(CourseClass.class.simpleName)
                .select(cayenneRuntime.newContext())
    }
    
    List<CourseClass> selectMore() {
        
        (ObjectSelect.query(CourseClass)
                .where(ExpressionFactory.inDbExp(CourseClass.ID_PK_COLUMN, '1001'))
                & CourseClass.COLLEGE.eq(college))
                .prefetch(CourseClass.COURSE.joint())
                .prefetch(CourseClass.COURSE.dot(Course.FIELD_CONFIGURATION_SCHEME).joint())
                .cacheStrategy(QueryCacheStrategy.SHARED_CACHE)
                .cacheGroup(CourseClass.class.simpleName)
                .select(cayenneRuntime.newContext())
    }
    
}
{code}



> Cayenne cache issue: 'SelectQuery' with prefetches loses relationships (null)
> -----------------------------------------------------------------------------
>
>                 Key: CAY-2349
>                 URL: https://issues.apache.org/jira/browse/CAY-2349
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 4.0.B1
>         Environment: JCacheModule, ehcache.
>            Reporter: Artyom Kravchenko
>
> 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:
> {code:java}
> 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())
>     }
>     
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)