Try this:

Example example = new Example();
Criteria criteria = example.createCriteria();
if (a == b) {
  criteria.andField1EqualTo(5);
}

if (c == f) {
  criteria.andField2EqualTo(5);
}

Jeff Butler


On Feb 10, 2008 1:56 PM, Jared Blitzstein <[EMAIL PROTECTED]> wrote:

> I have a case where I need to do some "if" logic before I know to add an
> and statement. I have a snippet like this:
>
> Example example = new Example();
>
>
> if (a==b) {
>
>   example.createCriteria().andField1EqualTo(5);
>
> }
>
>
> if (c==f) {
>
>   example.createCriteria().andField2EqualTo(5);
>
> }
>
>
> Doing this results in only one where clause,  "where Field1 = 5" and not like 
> "where Field1 = 5 and Field2 = 5" like I want. Am I using the correct syntax 
> or is there a different way to do this? Essentially I'm building the where 
> clause based on user input.
>
>

Reply via email to