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 Espen Rydningen <es...@rydningen.no> on 2006/04/25 21:43:19 UTC

QueryByExample - querying on same column with different values

Hi,

I'm new to Ibatis, so if this is a stupid question, you'll have to excuse
me. I've downloaded Abator for Eclipse and generated maps/DAOs and models.
In this example it's an agreement table between a buyer and a seller. This
table also got a status field the buyer and the seller for each agreement.
So my task is to get a list of agreements where the status for the buyer is
either 'A' for approved or 'P' for pending, and the status for the seller is
either 'A' or 'P'.

I've come this far:

AgreementIbatisExample example =  new AgreementIbatisExample();
example.setSellerStatus("A");
example.setSellerStatus_Indicator(AgreementIbatisExample.EXAMPLE_EQUALS);
example.setBuyerStatus("A");
example.setBuyerStatus_Indicator(AgreementIbatisExample.EXAMPLE_EQUALS);

AgreementIbatisDAO agreementDao =
IbatisDAOFactory.getDAO(AgreementIbatisDAO.class);
List<AgreementIbatis> list = agreementDao.selectByExample(example);

But this only gives med the list with both statuses is set to "A", I also
want the list to contain records where the statuses also is "P" and where
either is "P" or "A".

Is the answer to my task that I've got to do this operation 4 times, each
time changing the values in the parameters ([A,A] [A,P] [P,P] [P,A]) and
then combining the results in one result-list?

- Espen



Re: QueryByExample - querying on same column with different values

Posted by Jeff Butler <je...@gmail.com>.
The Abator query by example facility does not support this kind of where
clause currently, so you'll have to do the operation 4 times (sorry about
that).

Once we get support for nested iterate tags into iBATIS, then I'll change
Abator so that you can generate arbitrarily complex where clauses.

Jeff Butler


On 4/25/06, Espen Rydningen <es...@rydningen.no> wrote:
>
> Hi,
>
> I'm new to Ibatis, so if this is a stupid question, you'll have to excuse
> me. I've downloaded Abator for Eclipse and generated maps/DAOs and models.
> In this example it's an agreement table between a buyer and a seller. This
> table also got a status field the buyer and the seller for each agreement.
> So my task is to get a list of agreements where the status for the buyer
> is
> either 'A' for approved or 'P' for pending, and the status for the seller
> is
> either 'A' or 'P'.
>
> I've come this far:
>
> AgreementIbatisExample example =  new AgreementIbatisExample();
> example.setSellerStatus("A");
> example.setSellerStatus_Indicator(AgreementIbatisExample.EXAMPLE_EQUALS);
> example.setBuyerStatus("A");
> example.setBuyerStatus_Indicator(AgreementIbatisExample.EXAMPLE_EQUALS);
>
> AgreementIbatisDAO agreementDao =
> IbatisDAOFactory.getDAO(AgreementIbatisDAO.class);
> List<AgreementIbatis> list = agreementDao.selectByExample(example);
>
> But this only gives med the list with both statuses is set to "A", I also
> want the list to contain records where the statuses also is "P" and where
> either is "P" or "A".
>
> Is the answer to my task that I've got to do this operation 4 times, each
> time changing the values in the parameters ([A,A] [A,P] [P,P] [P,A]) and
> then combining the results in one result-list?
>
> - Espen
>
>
>