There is a bug in the Wonder PosgresqlPlugIn framework that make
it generates bad SQL expressions in some case (i.e. when having
more than two joins). There are more chance to encounter this bug
when using vertical mapping inheritance, like in this example:
[User] <---->> [UserContact] <<----> [Contact]
| / \
[Employe] [Address] [Phone]
In this case, when EOF build up the SQL expression to fetch
employe's addresses using the PosgresqlPlugIn, it does this:
SELECT
t0.CITY,
T1.CLASS_TYPE,
t0.LINE_1,
t0.LINE_2,
T1.FK_CONTACT_TYPE,
t0.FK_COUNTRY,
t0.FK_STATE,
t0.PK,
t0.ZIP_CODE
FROM
ADDRESS t0 INNER JOIN
CONTACT T1 USING (PK) INNER JOIN
USER_CONTACT T2 ON T1.PK = T2.PK_CONTACT INNER JOIN
USER T3 ON T2.PK_USER = T3.PK INNER JOIN
EMPLOYE T4 USING (PK)
WHERE
(T1.CLASS_TYPE = ? AND T4.PK = ?);
But this request fails with an exception telling "ERROR: common
column name "pk" appears more than once in left table". The
responsible are the two "USING (PK)" clauses, leading the
expression state to an ambiguous attribute reference. In the
framework code, this clause generation is done starting at line
165, in the assembleJoinClause(String, String, int) method in the
PosgresqlExpression class:
/* 165 */ if( destCols.equals( sourceCols ) ) {
/* 166 */ jc.joinCondition = " USING (" +
destCols.componentsJoinedByString( ", " ) + ")";
/* 167 */ } else {
[...]
/* 178 */ }
If the "USING ()" clause generation is removed, leaving all the
joins to be in the "ON ... = ..." form, then a non ambiguous SQL
expression is generated:
SELECT
[...]
FROM
ADDRESS t0 INNER JOIN
CONTACT T1 ON t0.PK = T1.PK INNER JOIN
USER_CONTACT T2 ON T1.PK = T2.PK_CONTACT INNER JOIN
USER T3 ON T2.PK_USER = T3.PK INNER JOIN
EMPLOYE T4 ON T3.PK = T4.PK
WHERE
(T1.CLASS_TYPE = ? AND T4.PK = ?);