views:

289

answers:

1

Hi,

I'm new to iBatis and I'm struggling with the and elements.

I want to iterate over a List of Book instances (say) that are passed in as a HashMap: MyParameters. The list will be called listOfBooks.

The clause of the overall SQL statement will therefore look like this:

<iterate prepend="AND" property="MyParameters.listOfBooks" conjunction="AND" open="(" close=")">
...
</iterate>

I also need to produce different SQL within the iterate elements depending on whether a property of each Book instance in the 'listOfBooks' List is null, or not.

So, I need a statement something like this:

 <iterate prepend="AND" property="MyParameters.listOfBooks" conjunction="AND" open="(" close=")">
        <isNull property="MyParameter.listOfBooks.title">
<!-- SQL clause #1 here -->

        </isNull>
  <isNotNull property="MyParameter.listOfBooks.title">
<!-- SQL clause #2 here -->
 </isNotNull>

When I do this I get an error message stating that there is no "READABLE" property named 'title' in my Book class. However, each Book instance does contain a title property, so I'm confused! I can only assuem that I have managled the syntax in trying to pinpoint the title of particular Book instance in listOfBooks. I'm struggling to find the correct technique for trying to achieve this. If anyone can advise a way forward I'd be grateful.

Thanks

A: 

I suppose

property="MyParameter.listOfBooks.title"

instructs Ibatis to lookup a title property in the MyParameter.listOfBooks object, which is actually a list. You don't want that, you want to lookup that property in each element of the list (the 'cursor', say).

In Ibatis, inside the <iterate> tag, the syntax MyParameter.listOfBooks[] is used to reference that element instead of the full list (ref), I don't know if it will work inside a tag attribute, you might try: either

<isNull property="MyParameter.listOfBooks[].title">

or perhaps even

<isNull property="title">

BTW, I don't know the DB you are using, but are you aware of the COALESCE function ?

leonbloy
Thanks for the references: I will definitely check those out. I had tried the bracketed syntax as I had a feeling myself that the syntax was targting the wrong entity. Unfortunately, that didn't work either. The underlying database is Oracle 10g but I wasn't aware of the COALESCE function. I'll look into that; thanks again
onoma