You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Jared Blitzstein <ja...@blitzstein.net> on 2008/02/10 20:56:00 UTC
Question about Abator and Java5 example building, I can't add a second and clause
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.
Re: Question about Abator and Java5 example building, I can't add a second and clause
Posted by Jared Blitzstein <ja...@blitzstein.net>.
Perfect, thank you.
On Feb 10, 2008, at 3:03 PM, Jeff Butler wrote:
> 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 <ja...@blitzstein.net>
> 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.
>
Re: Question about Abator and Java5 example building, I can't add a second and clause
Posted by Jeff Butler <je...@gmail.com>.
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 <ja...@blitzstein.net> 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.
>
>