I swear I’ve done this before and it’s worked fine, but it seems that with the query I have (below) I can’t map two columns of the same name (in this case ’email’) even when using “as” in my query. I’ve also tried without the “as” – just having ‘u.email assessorEmail’ and that query works as well, but with the same problem, the field just doesn’t appear in my results when I debug.
getQueryRunner().query("SELECT u.email AS assessorEmail, f.formid, f.firstName, f.surname, f.email, f.valid, f.invalidreason FROM users AS u RIGHT JOIN userforms AS uf ON u.id=uf.user LEFT JOIN forms AS f ON uf.form=f.formid WHERE u.role=? AND f.submitted=1 AND f.valid=0 ORDER BY u.email", new MapListHandler(), Role.ASSESSOR);
MySql result:
assessorEmail formid firstName surname email valid invalidreason
assessor@test.com 547 John Doe user@test.com 0
Eclipse->inspect variable:
[{valid=false, invalidreason=, email=user@test.com, surname=Doe, firstName=John, formid=547}]
If I remove f.email from the query, the u.email appears successfully as ’email’ (still not assessorEmail).
Is this a DbUtils thing? A QueryRunner thing? Even a MySql Java connector thing? I’m sure I’m missing something really obvious here…
After a little more digging I found a bug listing for this issue http://bugs.mysql.com/bug.php?id=32504. Seems to be an issue with the connector.
Adding “useOldAliasMetadataBehavior=true” as a parameter to the JDBC URL did the trick.