Re: multiple criteria on the same field

Andras Balogh <[email protected]> Fri, 08 May 2009 12:52:09 +0300
Newsgroups gmane.comp.jakarta.turbine.torque.user
Message-ID <[email protected]>
Hi,

You need to do something like:

criteria.add( dataIscrizioneInizio.and(dataIscrizioneFine)  ) ;

to add both Criterions in the same time to the Criteria.

Best regards,
Andras


Ivano Luberti wrote:
> Hello , I have searched the ml and googled for this.
> I have found 2 old email asking for this but with no answer.
>
> When I try to do this :
>
> Criteria criteria = new Criteria();
> Criterion dataIscrizioneInizio =
> criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime", 
> (Date) (formUser.getDataIscrizioneInizio()), Criteria.GREATER_EQUAL);   
>       
>
> dataIscrizioneInizio.setIgnoreCase(true);   
>
> criteria.add(dataIscrizioneInizio);
>
> Criterion dataIscrizioneFine =
> criteria.getNewCriterion(IscrizioniSocioPeer.TABLE_NAME, "starttime", 
> (Date) (formUser.getDataIscrizioneFine()), Criteria.LESS_EQUAL);           
>
> dataIscrizioneFine.setIgnoreCase(true);   
>
> criteria.add(dataIscrizioneFine);
>
> Only the last criterion is included in the where clause.
>
> I have stepped into the add(Criterion) method of the Criteria class and
> found this:
>
>     public Criteria add(Criterion c)
>     {
>         StringBuffer sb = new StringBuffer(c.getTable().length()
>                 + c.getColumn().length() + 1);
>         sb.append(c.getTable());
>         sb.append('.');
>         sb.append(c.getColumn());
>         super.put(sb.toString(), c);
>         return this;
>     }
>
> If I understand well , the map keys are based on the table and field
> names then it is not possible to add two criteria on the same field to
> produce sql like:
>
> SELECT * FROM table WHERE table.field>x AND table.field<y
>
> Can someone suggest the best practice to do this with Torque ?
>
>
>