You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Asaf Shakarchi <as...@raytech.co.il> on 2005/10/17 22:20:00 UTC

Question regarding Criterias

Hey,

 

I'm new to Torque, just finished the installation and I have a little
question which probably is obvious for most of you ;)

 

 

Assuming I have two tables 'field' table which is built as: 'field_id',
'field_name'

And another table named 'field_connector' which is built as:
'field_connector_id', 'field_id1','field_id2'

 

I'd like to end with a query such as:

 

SELECT * FROM field WHERE field_connector.FIELD_ID1= field.FIELD_ID OR
field_connector.FIELD_ID2 = field.FIELD_ID

 

I tried to do this by the following code:

 

Criteria crit = new Criteria();

Criteria.Criterion linkFieldConnectorToField1=
crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1, FieldPeer.FIELD_ID,
Criteria.EQUAL);

Criteria.Criterion linkFieldConnectorToField2=
crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2, FieldPeer.FIELD_ID,
Criteria.EQUAL);

Criteria.Criterion linkBothFieldConnectorToField=
linkFieldConnectorToField1.or(linkFieldConnectorToField2);

 

 

But it seems that the query that is built makes a WHERE condition where
fieldConnector.FIELD_ID1='field.FIELD_ID', of course it fails since the
expression equals a field name to a string (obviously because of the '')

 

 

I thought about using JOIN here, but JOINS always add one join to another
with AND between each JOIN.and I'd like to have an expression here with OR
condition.

 

 

Is there any way to do it?

 

 

Thanks in advanced,

 

Asaf.

 

 

 


RE: Question regarding Criterias

Posted by Thomas Fischer <tf...@apache.org>.

On Tue, 18 Oct 2005, Asaf Shakarchi wrote:

> Hey,
> Damn, why it's soooo complex to do such an easy task? :)
>
> Why Criterion class doesn't have adjoin func? Then it would be possible 
> to create two Criterions and use 'or' function between them,

Patches are appreciated :-)

>
> Well, here's my code anyway:
>
>
>
> Criteria crit = new Criteria();
>
> Criteria.Criterion linkFieldConnectorToField1 =
> crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1,FieldPeer.FIELD_ID,
> Criteria.EQUAL);
>
> Criteria.Criterion linkFieldConnectorToField2=
> crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2,FieldPeer.FIELD_ID,
> Criteria.EQUAL);
>
> Criteria.Criterion linkBothFieldConnectorToField =
> linkFieldConnectorToField1.or(linkFieldConnectorToField2);
>
> crit.add(linkBothFieldConnectorToField);
>
>
> Well, this result a fine query but compare the fields to strings, I don't
> understand, if the type of the field in the Criterions is PEER's field, why
> the generated query doesn't set a condition of a field and assume it's a
> text?

Sorry, I did not understand what the problem is. Can you please try to 
explain again ?

>
> Thanks a lot
> Asaf.
>

    Thomas

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


RE: Question regarding Criterias

Posted by Asaf Shakarchi <as...@raytech.co.il>.
Hey,
Damn, why it's soooo complex to do such an easy task? :)

Why Criterion class doesn't have adjoin func? Then it would be possible to
create two Criterions and use 'or' function between them,

Well, here's my code anyway:



Criteria crit = new Criteria();

Criteria.Criterion linkFieldConnectorToField1 =
crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1,FieldPeer.FIELD_ID,
Criteria.EQUAL);
			
Criteria.Criterion linkFieldConnectorToField2=
crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2,FieldPeer.FIELD_ID,
Criteria.EQUAL);
			
Criteria.Criterion linkBothFieldConnectorToField =
linkFieldConnectorToField1.or(linkFieldConnectorToField2);
			
crit.add(linkBothFieldConnectorToField);


Well, this result a fine query but compare the fields to strings, I don't
understand, if the type of the field in the Criterions is PEER's field, why
the generated query doesn't set a condition of a field and assume it's a
text?

Thanks a lot
Asaf.


-----Original Message-----
From: lti-1a8g@myamail.com [mailto:lti-1a8g@myamail.com] 
Sent: Tuesday, October 18, 2005 17:29
To: Apache Torque Users List
Subject: Re: Question regarding Criterias

Asaf Shakarchi wrote:

>Hey,
>
> 
>
>I'm new to Torque, just finished the installation and I have a little
>question which probably is obvious for most of you ;)
>
> 
>
> 
>
>Assuming I have two tables 'field' table which is built as: 'field_id',
>'field_name'
>
>And another table named 'field_connector' which is built as:
>'field_connector_id', 'field_id1','field_id2'
>
> 
>
>I'd like to end with a query such as:
>
> 
>
>SELECT * FROM field WHERE field_connector.FIELD_ID1= field.FIELD_ID OR
>field_connector.FIELD_ID2 = field.FIELD_ID
>
> 
>
>I tried to do this by the following code:
>
> 
>
>Criteria crit = new Criteria();
>
>Criteria.Criterion linkFieldConnectorToField1=
>crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1, FieldPeer.FIELD_ID,
>Criteria.EQUAL);
>
>Criteria.Criterion linkFieldConnectorToField2=
>crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2, FieldPeer.FIELD_ID,
>Criteria.EQUAL);
>
>Criteria.Criterion linkBothFieldConnectorToField=
>linkFieldConnectorToField1.or(linkFieldConnectorToField2);
>
> 
>
> 
>
>But it seems that the query that is built makes a WHERE condition where
>fieldConnector.FIELD_ID1='field.FIELD_ID', of course it fails since the
>expression equals a field name to a string (obviously because of the '')
>
> 
>
> 
>
>I thought about using JOIN here, but JOINS always add one join to another
>with AND between each JOIN.and I'd like to have an expression here with OR
>condition.
>
> 
>
> 
>
>Is there any way to do it?
>
> 
>
> 
>
>Thanks in advanced,
>
> 
>
>Asaf.
>  
>
Could you post the whole code (Criteria building AND the doSelect ...)
and the complete SQL query that is generated ?
Thanks.

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



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


Re: Question regarding Criterias

Posted by lt...@myamail.com.
Asaf Shakarchi wrote:

>Hey,
>
> 
>
>I'm new to Torque, just finished the installation and I have a little
>question which probably is obvious for most of you ;)
>
> 
>
> 
>
>Assuming I have two tables 'field' table which is built as: 'field_id',
>'field_name'
>
>And another table named 'field_connector' which is built as:
>'field_connector_id', 'field_id1','field_id2'
>
> 
>
>I'd like to end with a query such as:
>
> 
>
>SELECT * FROM field WHERE field_connector.FIELD_ID1= field.FIELD_ID OR
>field_connector.FIELD_ID2 = field.FIELD_ID
>
> 
>
>I tried to do this by the following code:
>
> 
>
>Criteria crit = new Criteria();
>
>Criteria.Criterion linkFieldConnectorToField1=
>crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1, FieldPeer.FIELD_ID,
>Criteria.EQUAL);
>
>Criteria.Criterion linkFieldConnectorToField2=
>crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2, FieldPeer.FIELD_ID,
>Criteria.EQUAL);
>
>Criteria.Criterion linkBothFieldConnectorToField=
>linkFieldConnectorToField1.or(linkFieldConnectorToField2);
>
> 
>
> 
>
>But it seems that the query that is built makes a WHERE condition where
>fieldConnector.FIELD_ID1='field.FIELD_ID', of course it fails since the
>expression equals a field name to a string (obviously because of the '')
>
> 
>
> 
>
>I thought about using JOIN here, but JOINS always add one join to another
>with AND between each JOIN.and I'd like to have an expression here with OR
>condition.
>
> 
>
> 
>
>Is there any way to do it?
>
> 
>
> 
>
>Thanks in advanced,
>
> 
>
>Asaf.
>  
>
Could you post the whole code (Criteria building AND the doSelect ...)
and the complete SQL query that is generated ?
Thanks.

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


RE: Question regarding Criterias

Posted by Asaf Shakarchi <as...@raytech.co.il>.
Hey,

Thanks for answering,

Are there any details of how addSelectColumn works? I don't see anything
related to it by the link you've specified nor anything else related, can
you point me to something more specific?

Thanks,

Asaf.


-----Original Message-----
From: Thomas Fischer [mailto:fischer@seitenbau.net] 
Sent: Tuesday, October 18, 2005 09:23
To: Apache Torque Users List
Subject: RE: Question regarding Criterias






Hi,

Sorry, this is not possible at the moment in a simple way. For joins, you
would usually use Criteria.addJoin(), but at the moment, Torque only
supports join clauses which are connected with an 'AND'.

It might be possible to create your query using the methods
Criteria.addSelectColumn() to add the colums of the joined table, and use
the method described in
http://db.apache.org/torque/releases/torque-3.2-rc2/runtime/peers-howto.html

to create the or'd condition. Note: The DoSelectJoinYYY described in the
same section will NOT help you, as they produce a simple join.

Alternatively, you can also produce a double join using Criteria.addJoin()
and join the field_connector table twice. This would imply using aliases
(Criteria.addAlias)

        Thomas

"Asaf Shakarchi" <as...@raytech.co.il> schrieb am 17.10.2005 22:20:00:

> Hey,
>
>
>
> I'm new to Torque, just finished the installation and I have a little
> question which probably is obvious for most of you ;)
>
>
>
>
>
> Assuming I have two tables 'field' table which is built as: 'field_id',
> 'field_name'
>
> And another table named 'field_connector' which is built as:
> 'field_connector_id', 'field_id1','field_id2'
>
>
>
> I'd like to end with a query such as:
>
>
>
> SELECT * FROM field WHERE field_connector.FIELD_ID1= field.FIELD_ID OR
> field_connector.FIELD_ID2 = field.FIELD_ID
>
>
>
> I tried to do this by the following code:
>
>
>
> Criteria crit = new Criteria();
>
> Criteria.Criterion linkFieldConnectorToField1=
> crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1, FieldPeer.FIELD_ID,
> Criteria.EQUAL);
>
> Criteria.Criterion linkFieldConnectorToField2=
> crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2, FieldPeer.FIELD_ID,
> Criteria.EQUAL);
>
> Criteria.Criterion linkBothFieldConnectorToField=
> linkFieldConnectorToField1.or(linkFieldConnectorToField2);
>
>
>
>
>
> But it seems that the query that is built makes a WHERE condition where
> fieldConnector.FIELD_ID1='field.FIELD_ID', of course it fails since the
> expression equals a field name to a string (obviously because of the '')
>
>
>
>
>
> I thought about using JOIN here, but JOINS always add one join to another
> with AND between each JOIN.and I'd like to have an expression here with
OR
> condition.
>
>
>
>
>
> Is there any way to do it?
>
>
>
>
>
> Thanks in advanced,
>
>
>
> Asaf.
>
>
>
>
>
>
>


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



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


RE: Question regarding Criterias

Posted by Thomas Fischer <fi...@seitenbau.net>.




Hi,

Sorry, this is not possible at the moment in a simple way. For joins, you
would usually use Criteria.addJoin(), but at the moment, Torque only
supports join clauses which are connected with an 'AND'.

It might be possible to create your query using the methods
Criteria.addSelectColumn() to add the colums of the joined table, and use
the method described in
http://db.apache.org/torque/releases/torque-3.2-rc2/runtime/peers-howto.html

to create the or'd condition. Note: The DoSelectJoinYYY described in the
same section will NOT help you, as they produce a simple join.

Alternatively, you can also produce a double join using Criteria.addJoin()
and join the field_connector table twice. This would imply using aliases
(Criteria.addAlias)

        Thomas

"Asaf Shakarchi" <as...@raytech.co.il> schrieb am 17.10.2005 22:20:00:

> Hey,
>
>
>
> I'm new to Torque, just finished the installation and I have a little
> question which probably is obvious for most of you ;)
>
>
>
>
>
> Assuming I have two tables 'field' table which is built as: 'field_id',
> 'field_name'
>
> And another table named 'field_connector' which is built as:
> 'field_connector_id', 'field_id1','field_id2'
>
>
>
> I'd like to end with a query such as:
>
>
>
> SELECT * FROM field WHERE field_connector.FIELD_ID1= field.FIELD_ID OR
> field_connector.FIELD_ID2 = field.FIELD_ID
>
>
>
> I tried to do this by the following code:
>
>
>
> Criteria crit = new Criteria();
>
> Criteria.Criterion linkFieldConnectorToField1=
> crit.getNewCriterion(FieldConnectorPeer.FIELD_ID1, FieldPeer.FIELD_ID,
> Criteria.EQUAL);
>
> Criteria.Criterion linkFieldConnectorToField2=
> crit.getNewCriterion(FieldConnectorPeer.FIELD_ID2, FieldPeer.FIELD_ID,
> Criteria.EQUAL);
>
> Criteria.Criterion linkBothFieldConnectorToField=
> linkFieldConnectorToField1.or(linkFieldConnectorToField2);
>
>
>
>
>
> But it seems that the query that is built makes a WHERE condition where
> fieldConnector.FIELD_ID1='field.FIELD_ID', of course it fails since the
> expression equals a field name to a string (obviously because of the '')
>
>
>
>
>
> I thought about using JOIN here, but JOINS always add one join to another
> with AND between each JOIN.and I'd like to have an expression here with
OR
> condition.
>
>
>
>
>
> Is there any way to do it?
>
>
>
>
>
> Thanks in advanced,
>
>
>
> Asaf.
>
>
>
>
>
>
>


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