[OJB-developers] problem with path expressions and extents
Brought to you by:
thma
From: Jakob B. <jbr...@ho...> - 2002-05-23 17:22:57
|
hi all, we have a general problem when using path expression and extents. the following test case reads a cd (an extent of article) and then tries to read the product group using the relationship 'allArticlesInGroup' belonging to this cd in a second query. the second query cannot find the productgroup because 'allArticlesInGroup' refers to Article and not to Cd, so the article-table is used in the join: SELECT A0.Kategorie_Nr,A0.KategorieName,A0.Beschreibung FROM Kategorien A0 INNER JOIN Artikel A1 ON A0.Kategorie_Nr=A1.Kategorie_Nr WHERE A1.Artikel_Nr = ? the query returning the correct result: SELECT A0.Kategorie_Nr,A0.KategorieName,A0.Beschreibung FROM Cds A0 INNER JOIN Artikel A1 ON A0.Kategorie_Nr=A1.Kategorie_Nr WHERE A1.Artikel_Nr = ? i think we need some kind of hints for path expression, so SqlStatement knows which tables to use. the hints can be set on Criteria or Query level: query.useClass("AllProductsInGroup", Cd.class) Query query; Criteria crit; CdArticle cd; ProductGroup pg; System.out.println("\nread a single cd"); crit = new Criteria(); crit.addEqualTo("articleId", new Integer(200)); query = new QueryByCriteria(CdArticle.class, crit); cd = (CdArticle) broker.getObjectByQuery(query); System.out.println(cd); System.out.println("\nread product group for cd"); crit = new Criteria(); crit.addEqualTo("allArticlesInGroup.articleId",new Integer(cd.getArticleId())); query = new QueryByCriteria(ProductGroup.class, crit); pg = (ProductGroup) broker.getObjectByQuery(query); System.out.println(pg); this kind of query may look a little exotic in the above sample, but it's the kind of query used in non decomposed m:n relationship. so we definitely need a solution here. any help will be appreciated. jakob |