You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Arturo Perez <ap...@hayesinc.com> on 2006/06/19 15:13:15 UTC
Problem traversing relationships - need hint
Hi all,
I had this problem with the last beta and was hoping RC1 would fix but
no such luck.
I have 4 entities, Article, ArticleMeta, ArticleCategory and
ArticleCategoryLink. ArticleCategoryLink is just a join table
between ArticleMeta and ArticleCategory. (I don't do flattened
relationships yet). ArticleMeta has a FK/relationship
to Article.
If I do this
Iterator i = articleCategory.getArticles().iterator();
while (i.hasNext()) {
ArticleCategoryLink acl = (ArticleCategoryLink)i.next();
ArticleMeta am = acl.getLatestArticle();
Article a = am.getArticle();
}
The article is null but if I run an Expression I get what I expect:
Expression exp =
ExpressionFactory.matchExp("activeArticle.categories.category",
category);
exp = exp.andExp(
Expression.fromString("latestArticle.article activeArticle.article"));
DataContext dbContext = ArticleManager.getArticleManager().getDataContext();
SelectQuery catQuery = new SelectQuery(Article.class, exp);
Any suggestions on where to look for improperly defined model etc?
tia,
arturo
Re: Problem traversing relationships - need hint
Posted by Andrus Adamchik <an...@objectstyle.org>.
The query certainly looks fishy. I suspect this may be related to
this issue:
http://issues.apache.org/cayenne/browse/CAY-447
Now the question is whether your relationship problem is also related
to that. I guess it would help if you post your DataMap XML subset
containing the 4 entities in question.
Andrus
On Jun 19, 2006, at 8:32 PM, Arturo Perez wrote:
> Andrus Adamchik <andrus <at> objectstyle.org> writes:
>
>>
>>
>> On Jun 19, 2006, at 5:13 PM, Arturo Perez wrote:
>>
>>> Iterator i = articleCategory.getArticles().iterator();
>>> while (i.hasNext()) {
>>> ArticleCategoryLink acl = (ArticleCategoryLink)i.next();
>>> ArticleMeta am = acl.getLatestArticle();
>>> Article a = am.getArticle();
>>> }
>>>
>>> The article is null but if I run an Expression I get what I expect:
>>>
>>> Expression exp =
>>> ExpressionFactory.matchExp("activeArticle.categories.category",
>>> category);
>>> exp = exp.andExp(
>>> Expression.fromString("latestArticle.article
>>> activeArticle.article"));
>>
>> The last expression looks strange (I am surprised it compiles). What
>> SQL is generated for the query?
>>
>> Andrus
>>
>>
>
> It looks like the equal sign went away. It should be
> "latestArticle.article = activeArticle.article"
>
> That last expression is intended to limit results to the current
> articles.
> Everything has backissues that should be ignored for the above.
> The SQL
> is a 4-way join:
>
>
> 2006-06-19 12:25:21,249 [http-8316-Processor24] WARN
> org.objectstyle.cayenne.access.QueryLogger- SELECT DISTINCT
> t0.ARTICLE_ID,
> t0.ARTICLE_META_ID FROM ARTICLE t0, ARTICLE_META t1,
> ARTICLE_CATEGORY_LINK t2, ARTICLE_META t3 WHERE t0.ARTICLE_ID =
> t1.ACTIVE_ARTICLE_ID AND t1.ARTICLE_META_ID = t2.ARTICLE_META_ID AND
> t0.ARTICLE_META_ID = t3.ARTICLE_META_ID AND ((t2.CATEGORY_ID = ?) AND
> (t1.ACTIVE_ARTICLE_ID = t1.ACTIVE_ARTICLE_ID)) [bind: 1042]
> 2006-06-19 12:25:23,608 [http-8316-Processor24] WARN
> org.objectstyle.cayenne.access.QueryLogger- === returned 91 rows.
> - took
> 2359 ms.
>
>
>
> I suppose I should change the above to a matchInExp to cut down on
> the join
> but I'm more concerned about the null. Although, looking at that
> SQL, the
> last AND clause seems incorrect.
>
> -arturo
Re: Problem traversing relationships - need hint
Posted by Arturo Perez <ap...@hayesinc.com>.
Andrus Adamchik <andrus <at> objectstyle.org> writes:
>
>
> On Jun 19, 2006, at 5:13 PM, Arturo Perez wrote:
>
> > Iterator i = articleCategory.getArticles().iterator();
> > while (i.hasNext()) {
> > ArticleCategoryLink acl = (ArticleCategoryLink)i.next();
> > ArticleMeta am = acl.getLatestArticle();
> > Article a = am.getArticle();
> > }
> >
> > The article is null but if I run an Expression I get what I expect:
> >
> > Expression exp =
> > ExpressionFactory.matchExp("activeArticle.categories.category",
> > category);
> > exp = exp.andExp(
> > Expression.fromString("latestArticle.article
> > activeArticle.article"));
>
> The last expression looks strange (I am surprised it compiles). What
> SQL is generated for the query?
>
> Andrus
>
>
It looks like the equal sign went away. It should be
"latestArticle.article = activeArticle.article"
That last expression is intended to limit results to the current articles.
Everything has backissues that should be ignored for the above. The SQL
is a 4-way join:
2006-06-19 12:25:21,249 [http-8316-Processor24] WARN
org.objectstyle.cayenne.access.QueryLogger- SELECT DISTINCT t0.ARTICLE_ID,
t0.ARTICLE_META_ID FROM ARTICLE t0, ARTICLE_META t1,
ARTICLE_CATEGORY_LINK t2, ARTICLE_META t3 WHERE t0.ARTICLE_ID =
t1.ACTIVE_ARTICLE_ID AND t1.ARTICLE_META_ID = t2.ARTICLE_META_ID AND
t0.ARTICLE_META_ID = t3.ARTICLE_META_ID AND ((t2.CATEGORY_ID = ?) AND
(t1.ACTIVE_ARTICLE_ID = t1.ACTIVE_ARTICLE_ID)) [bind: 1042]
2006-06-19 12:25:23,608 [http-8316-Processor24] WARN
org.objectstyle.cayenne.access.QueryLogger- === returned 91 rows. - took
2359 ms.
I suppose I should change the above to a matchInExp to cut down on the join
but I'm more concerned about the null. Although, looking at that SQL, the
last AND clause seems incorrect.
-arturo
Re: Problem traversing relationships - need hint
Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jun 19, 2006, at 5:13 PM, Arturo Perez wrote:
> Iterator i = articleCategory.getArticles().iterator();
> while (i.hasNext()) {
> ArticleCategoryLink acl = (ArticleCategoryLink)i.next();
> ArticleMeta am = acl.getLatestArticle();
> Article a = am.getArticle();
> }
>
> The article is null but if I run an Expression I get what I expect:
>
> Expression exp =
> ExpressionFactory.matchExp("activeArticle.categories.category",
> category);
> exp = exp.andExp(
> Expression.fromString("latestArticle.article
> activeArticle.article"));
The last expression looks strange (I am surprised it compiles). What
SQL is generated for the query?
Andrus