This sounds familiar. There is an ancient Trac ticket dealing with this case. It happens when you use select() with an empty projection while selecting from multiple tabes with identical fields (i.e. SELECT * FROM A, B). In that case, there is some ambiguity in the lookup of fields in a FieldProvider, in case of which, the first "matching" field is returned. The workaround, as far as I remember, is to explicitly specify the projection (select part).
Anyway, that is not a minor issue. Aliasing shouldn't be needed in this case. Trac seems to be down. I'll have a look into it tomorrow Cheers and thanks for reporting! Lukas 2012/4/23 ericjs <[email protected]>: > I ran into this in 2.1.0...haven't tried it with the new release yet, > as I didn't see anything in the list of fixes that sounded relevant. > And somehow I missed that there was 2.2.x series...I'll be upgrading > to that soon. > > But what I am seeing is jooq giving me the wrong column value, in a > situation like this: > > PublicFactory create = new PublicFactory(conn); > Result<Record> result = > create.select().from(A) > .join(B) > .on(A.ID.equal(B.A_ID)) > .join(ORGANIZATION) ; > ... > > rec.getValue(rec.getField(B.ID)); // this ends up giving me the value > for A.ID! > > This is simplified of course, but hopefully the gist is obvious > enough...the result of the join has two "id" columns one from a and > one from b, and when I ask for b's id, it gives me a's. > > Now I realize the columns really are ambiguous in the underlying SQL > and result. And I've already fixed my code to use aliases in the > select. In fact normally when writing SQL directly I simply ALWAYS use > column aliases (and table aliases)..it makes life simpler and actually > makes the syntax shorter. > > But since Jooq is allowing me to specify B.ID, it seems to me it ought > to do whatever it needs to ensure that this is what it gives me. > (Perhaps joog should generate aliases in the sql and map them to the > table field names.) > > Apologies if this is already made irrelevant by Jooq 2.2 or if it is > in the bug tracking system already and I failed to find it.
