You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Viczián István <vi...@freemail.hu> on 2003/09/09 09:57:22 UTC

Join tables that has fields with same name

Hi,

I would like to join two table, and they are in 1:n relation, and they have
a field with same name. If
I add a criteria to this, I get an exception. This exception says,
that the field is _ambiguous_.
I've logged the SQL query with P6Spy, and it is true, the name of the field
appears in the select statement without qualification, so the name of the
field is
really ambiguous. I've tried qualify with the table name, but it is not
good, it should be
qualified with the alias.

Concretely symbolically:
table A (a_id, samename);
table B (b_id, a_id, samename, prop);

A:B = 1:N

Criteria c1; c.addEquals("samename", "blahblah"); // criteria for the
Criteria c1; c.addEquals("b.prop", 1); // join
Query for table A, request for A objects

So the exception says, that the samename is ambiguous.
The generated sql is something like this:

select a_id, samename from A a0 INNER JOIN B a1 WHERE samename = 'blahblah'
and
a0.a_id = a1.b_id and a1.prop = 1;

So the samename field appears without alias qualification.
How should I correct my code without renaming columns to individual name?

Thank you,

	Istvan

---
Viczián István [Viczi] (viczus@freemail.hu)
Honlap: http://dragon.unideb.hu/~vicziani
Mobil#: +36(30)3656804 ICQ#: 15803584


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Join tables that has fields with same name

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi istvan,

this looks like a problem in your mapping. if ojb finds descriptors for 
the fields it prefixes them with a table alias (a.name).
if no field is found the name from the criteria is used.

hth
jakob

Viczián István wrote:

>Hi,
>
>I would like to join two table, and they are in 1:n relation, and they have
>a field with same name. If
>I add a criteria to this, I get an exception. This exception says,
>that the field is _ambiguous_.
>I've logged the SQL query with P6Spy, and it is true, the name of the field
>appears in the select statement without qualification, so the name of the
>field is
>really ambiguous. I've tried qualify with the table name, but it is not
>good, it should be
>qualified with the alias.
>
>Concretely symbolically:
>table A (a_id, samename);
>table B (b_id, a_id, samename, prop);
>
>A:B = 1:N
>
>Criteria c1; c.addEquals("samename", "blahblah"); // criteria for the
>Criteria c1; c.addEquals("b.prop", 1); // join
>Query for table A, request for A objects
>
>So the exception says, that the samename is ambiguous.
>The generated sql is something like this:
>
>select a_id, samename from A a0 INNER JOIN B a1 WHERE samename = 'blahblah'
>and
>a0.a_id = a1.b_id and a1.prop = 1;
>
>So the samename field appears without alias qualification.
>How should I correct my code without renaming columns to individual name?
>
>Thank you,
>
>	Istvan
>
>---
>Viczián István [Viczi] (viczus@freemail.hu)
>Honlap: http://dragon.unideb.hu/~vicziani
>Mobil#: +36(30)3656804 ICQ#: 15803584
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org