You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Graham Leggett <mi...@sharp.fm> on 2004/04/01 14:29:01 UTC

Criteria and OR

Hi all,

I have a criteria that is to generate a SQL statement "where x=a or y=a" 
like so:

criteria.or(PolicyNoteReversalPeer.REVERSAL_ID, a);
criteria.or(PolicyNoteReversalPeer.ORIGINAL_ID, a);

This criteria generates the following sql:

SELECT  FROM policy_note_reversal WHERE 
policy_note_reversal.REVERSAL_ID=29156 AND 
policy_note_reversal.ORIGINAL_ID=29156

Does anyone know why an OR would be rendered as an AND?

I am using torque v3.1.

Regards,
Graham
--


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


Re: Criteria and OR

Posted by Graham Leggett <mi...@sharp.fm>.
David Zverina wrote:

> You're probably adding criteria instead of making Criterions and or-ing
> them first. The following code fragment works and will probably do what
> you need.

Thanks!

Is it possible to add this to the documentation of the or() methods in 
Criteria? It implies by the name of the method "or" that when added it 
should say "or".

Can this also be added to the Criteria howto documentation?

Regards,
Graham
--


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


Re: Criteria and OR

Posted by David Zverina <dz...@zverina.co.uk>.
You're probably adding criteria instead of making Criterions and or-ing
them first. The following code fragment works and will probably do what
you need.

Regards,

David.
------

    Criteria c = new Criteria();
    Criteria.Criterion x = c.getNewCriterion(ItemPeer.ITEMID, new
Integer(4), Criteria.EQUAL);
    Criteria.Criterion y = c.getNewCriterion(ItemPeer.STAGEID, new
Integer(10), Criteria.EQUAL);
    c.add(x.or(y));


On Thu, 2004-04-01 at 13:29, Graham Leggett wrote:
> Hi all,
> 
> I have a criteria that is to generate a SQL statement "where x=a or y=a" 
> like so:
> 
> criteria.or(PolicyNoteReversalPeer.REVERSAL_ID, a);
> criteria.or(PolicyNoteReversalPeer.ORIGINAL_ID, a);
> 
> This criteria generates the following sql:
> 
> SELECT  FROM policy_note_reversal WHERE 
> policy_note_reversal.REVERSAL_ID=29156 AND 
> policy_note_reversal.ORIGINAL_ID=29156
> 
> Does anyone know why an OR would be rendered as an AND?
> 
> I am using torque v3.1.
> 
> Regards,
> Graham
> --
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org
> 


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


RE: Criteria and OR

Posted by Daniel Huang <da...@cisco.com>.
Try

criteria.add(PolicyNoteReversalPeer.REVERSAL_ID, a);
Criteria.Criterion critOrigId =
criteria.getNewCriterion(PolicyNoteReversalPeer.ORIGINAL_ID, a);
criteria.or(critOrigId);

Regards,
Daniel

-----Original Message-----
From: Graham Leggett [mailto:minfrin@sharp.fm]
Sent: Thursday, April 01, 2004 4:29 AM
To: torque-dev@db.apache.org
Subject: Criteria and OR

Hi all,

I have a criteria that is to generate a SQL statement "where x=a or y=a"
like so:

criteria.or(PolicyNoteReversalPeer.REVERSAL_ID, a);
criteria.or(PolicyNoteReversalPeer.ORIGINAL_ID, a);

This criteria generates the following sql:

SELECT  FROM policy_note_reversal WHERE
policy_note_reversal.REVERSAL_ID=29156 AND
policy_note_reversal.ORIGINAL_ID=29156

Does anyone know why an OR would be rendered as an AND?

I am using torque v3.1.

Regards,
Graham
--


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


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