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 Guido Beutler <gb...@catsoft.de> on 2006/04/06 16:01:03 UTC

Query about more than one table

Hi,

I have a problem building  query about more than one table when the field in a where clause with OJB 1.0.4
occur in more than one table with the same name.
In SQL the following would work:

select * from table_a A0, table_b A1 where A0.key=A1.key and A0.key=5 ;

OJB builds a query where A0 and A! for the key ist correctly set.
My Problem is at the Criteria where I would set:

crit.addEqualTo("A0.key",key);

This causes a NullPointer at  broker.getCollectionByQuery(q);

If I set  the same without the A0

crit.addEqualTo("key",key);

There is no NullPointer but a SQL Exception which tells me that key is ambiguous.
How can I build queries like this? Thanks in advance,

best regards,

Guido

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


Re: Query about more than one table

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

yiu should not use column-names in your queries. use attribute-names 
instead.

please post the relevant parts of the repository.xml.

jakob

Guido Beutler schrieb:
> Hi,
> 
> I have a problem building  query about more than one table when the field in a where clause with OJB 1.0.4
> occur in more than one table with the same name.
> In SQL the following would work:
> 
> select * from table_a A0, table_b A1 where A0.key=A1.key and A0.key=5 ;
> 
> OJB builds a query where A0 and A! for the key ist correctly set.
> My Problem is at the Criteria where I would set:
> 
> crit.addEqualTo("A0.key",key);
> 
> This causes a NullPointer at  broker.getCollectionByQuery(q);
> 
> If I set  the same without the A0
> 
> crit.addEqualTo("key",key);
> 
> There is no NullPointer but a SQL Exception which tells me that key is ambiguous.
> How can I build queries like this? Thanks in advance,
> 
> best regards,
> 
> Guido
> 
> ---------------------------------------------------------------------
> 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