I've found that if I use ExpressionFactory.matchDbExp for DbEntity.setQualifier, cayenne use wrong aliases when building join queries. And if I use ExpressionFactory.matchExp for DbEntity.setQualifier, cayenne build joins with correct aliases. Using matchExp instead of matchDbExp for DbEntity looks wired, but it works. So I've found a workaround, but not sure, is it a bug or a feature.
2017-12-11 17:31 GMT+03:00 Владимир Сухинин <[email protected]>: > We have a database where all entities have a qualifier for "deleted" > field, which is added via DbEntity.setQualifier(Expression) during > DataMap loading. > When we create a SelectQuery, this qualifiers added in join "ON" node with > wrong table alias. > So our query looks like this: > SELECT DISTINCT t0.CUSTOMERID AS c0, > UPPER(t0.CUSTOMERLASTNAME) AS c1 > FROM CUSTOMER t0 > LEFT JOIN CUSTOMER_GROUP t1 > ON (t0.CUSTOMERID = t1.CUSTOMERID > AND t0.DELETED = 0) > JOIN GROUP t2 > ON (t1.GROUPID = t2.GROUPID > AND t0.DELETED = 0) > WHERE (t2.GROUPTYPEID = 101100100145) > AND (t0.DELETED = 0) > ORDER BY UPPER(t0.CUSTOMERLASTNAME) > ; > Earlier we've used cayenne-3.0RC3, and there queries with same DataMap and > qualifiers creates correctly > SELECT DISTINCT t0.CUSTOMERID, > UPPER(t0.CUSTOMERLASTNAME) > FROM CUSTOMER t0 > LEFT JOIN CUSTOMER_GROUP t1 > ON (t0.CUSTOMERID = t1.CUSTOMERID > AND t1.DELETED = 0) > JOIN GROUP t2 > ON (t1.GROUPID = t2.GROUPID > AND t2.DELETED = 0) > WHERE (t2.GROUPTYPEID = 101100100145) > AND (t0.DELETED = 0) > ORDER BY UPPER(t0.CUSTOMERLASTNAME) > ; > > -- > Vladimir Suhinin >
