0

I've got an object of the class A in 2 ways relationships with objects of classes B, C and D.

So I could do (with "a" an object of type A):

B b = a.getB();
A a1 = a.getB().getA(); // and a1 would be equal to a

When I do a SelectQuery on A with prefetchs on the relationship from A to B, C and D, all is fine. But If I add a prefetch on the relationship from B to A, then A lose the relationship from A to C and D or it doesn't do anything. I mean by "lose" that they have been invalidated.

Is that normal? Why is it so?

Notes: I'm using Cayenne 3.0.2 and disjoint prefetchs semantics.

Example 1 (as explained above):

SelectQuery query = new SelectQuery(A.class);
query.addPrefetch("b").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
query.addPrefetch("c").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
query.addPrefetch("d").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
query.addPrefetch("b.a").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
List<?> res= context.performQuery(query);

Example 2 (which is probably the same problem):

SelectQuery query = new SelectQuery(A.class);
query.addPrefetch("b").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
query.addPrefetch("c").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
List<?> res= context.performQuery(query);

then later

SelectQuery query = new SelectQuery(A.class);
query.addPrefetch("d").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
List<?> res= context.performQuery(query);

then the relationships with b and c are invalidated or the last prefetch is ignored. Sometimes b and c would be set to null though they are not null.

thanks

Adrien
  • 7
  • 5
  • Could you show a sequence of queries that leads to this issue? Also I would recommend to check it out with Cayenne 3.1, which is on the verge of a final release now. – andrus_a Sep 19 '14 at 07:59
  • @andrus_a I've just checked with cayenne 3.1RC1. It is exactly the same. I've added two examples to my question to make it clearer. – Adrien Sep 19 '14 at 13:13

1 Answers1

0

After some research, this appears to be the problem discussed in CAY-1695 Jira. It is caused by same objects appearing in the main query and subqueries, confusing prefetch processing code. The fix is only available on master (i.e. 3.2) and is not yet officially released. So one way to get it is to clone Cayenne from GitHub and do your own build. (But ping me if you run into trouble with that, I can post the binaries somewhere).

andrus_a
  • 2,528
  • 1
  • 16
  • 10
  • Thanks, I think I'm going to fix that by changing all bidirectional relationships into single direction ones and implement the missing getters in our application. – Adrien Sep 23 '14 at 08:46
  • Not sure switching from 2-way to 1-way relationships is going to help. A more sure way to work around this is to see that prefetches do not point to the original entity. – andrus_a Sep 23 '14 at 10:08
  • I've got exactly the same problem with: `SelectQuery query = new SelectQuery(A.class); query.addPrefetch("b").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS); query.addPrefetch("c").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS); List> res= context.performQuery(query);` then: `SelectQuery query = new SelectQuery(B.class); query.addPrefetch("a").setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS); List> res= context.performQuery(query);` – Adrien Sep 23 '14 at 13:14