[ 
https://issues.apache.org/jira/browse/CAY-1975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14233254#comment-14233254
 ] 

jotpe commented on CAY-1975:
----------------------------

Clear...

Class:
{code}
public class HelperCayenne {
        public static void main(String[] args) {
                Logger LOG = Logger.getGlobal();
                
                int id = new Integer(System.getProperty("id"));

                ServerRuntime runtime = new ServerRuntime(
                                GlobalProperties.CAYENNE_CONFIGURATION_FILE);
                ObjectContext context = runtime.getContext();
                
                String sql = "SELECT * FROM israelnationaltrail where id = 
#bind($currentId)";
                SQLTemplate query = new SQLTemplate(Israelnationaltrail.class, 
sql);
                query.setParameters(Collections.singletonMap("currentId", id));

                Israelnationaltrail israelnationaltrail = (Israelnationaltrail) 
Cayenne.objectForQuery(
                                context, query);
                LOG.info("tags:"+new 
ArrayList<Tag>(israelnationaltrail.getTags()));
                
                query.addPrefetch("tags");

                israelnationaltrail = (Israelnationaltrail) 
Cayenne.objectForQuery(
                                context, query);
                LOG.info("tags:"+new 
ArrayList<Tag>(israelnationaltrail.getTags()));

                runtime.shutdown();
        }
}
{code}

Log:
{noformat}
 287  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - +++ Connecting: SUCCESS.
 322  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - Detected and installed 
adapter: org.apache.cayenne.dba.postgres.PostgresAdapter
 323  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - --- transaction started.
 421  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - SELECT * FROM 
israelnationaltrail where id = ? [bind: 1:1128]
 469  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - === returned 1 row. - took 48 
ms.
 471  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - +++ transaction committed.
 514  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - --- transaction started.
 529  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - SELECT DISTINCT "t0"."id", 
"t0"."name" FROM "public"."tag" "t0" JOIN "public"."join_inttag" "t1" ON 
("t0"."id" = "t1"."tag_id") WHERE "t1"."int_id" = ? [bind: 1->int_id:1128] - 
prepared in 11 ms.
 533  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - === returned 1 row. - took 16 
ms.
 533  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - +++ transaction committed.
 Dez 03, 2014 7:07:27 PM net.jotpe.HelperCayenne main
INFORMATION: tags:[class net.jotpe.data.Tag id:360 name:train]
537  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - --- transaction started.
 537  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - SELECT * FROM 
israelnationaltrail where id = ? [bind: 1:1128]
 539  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - === returned 1 row. - took 2 
ms.
 539  [net.jotpe.HelperCayenne.main()] INFO  
org.apache.cayenne.log.CommonsJdbcEventLogger  - +++ transaction committed.
 Dez 03, 2014 7:07:27 PM net.jotpe.HelperCayenne main
{noformat}

> Unexpected null value when prefetching with Cayenne.objectForQuery
> ------------------------------------------------------------------
>
>                 Key: CAY-1975
>                 URL: https://issues.apache.org/jira/browse/CAY-1975
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.1
>            Reporter: jotpe
>              Labels: Prefetching, objectforquery
>
> Querying a select query with addPrefetch over Cayenne.objectForQuery results 
> in receiving null values for these prefetches. Without addPrefetch, the 
> relations are loaded correctly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to