Interesting iBATIS Data Mapper issue

June 20, 2005

This is one of those issues where I’m not sure it’s a feature or a bug. In iBATIS, you can use a parameterMap is to define an ordered list of parameters that match up with the value tokens passed along to your PreparedStatement. Here’s a simple example from the doc:

 

    
        
        
    

    
        insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?);
    

So parameterMaps work great as you can create a Map instead of a concrete class to pass into the application. I typically use a JavaBean for parameters but will use Maps as a quick workaround for simple quick application. Today I discovered that you couldn’t use parameterMaps if you are only passing in just1 parameter. If you try, you end up getting an SQLException with a ‘Parameter index out of range’ message.

Reading the doc seems to indicate that this is a feature as the doc reads:

If you are in a situation where it is not necessary or convenient to write a JavaBean class, and a single primitive type parameter won’t do (e.g. there are multiple parameters), you can use a Map (e.g. HashMap, TreeMap) as a parameter object.

So the clear implication is that you only want to use a Map if there are multiple parameters even though the doc doesn’t clearly state that. Just thought it was interesting. I’m downloading the code as we speak – hope to figure out the real cause and maybe submit a patch or a Jira issue at the very least.

Advertisements

4 Responses to “Interesting iBATIS Data Mapper issue”

  1. Ady said

    hmm..why would you want to use a parameterMap for passing just one value,knowing fully well that a #value# is sufficient to replace the parameter in the query?

    Just out of curiosity…are you bored?

  2. 🙂 Good question. The only reason I even found this bug or feature was because I just added a new query to my existing list and simply cloned the query above. All of the other parameterMaps had more 2 or more attributes and I just happen to add a new select that only took 1 parameter.

  3. Ady said

    IMHO this may neither be a bug nor a feature,but a rightful way to stop you from doing the wrongful thing.

    good luck patching…but I recommend investigating other useful features a worthwhile investment of your precious time.

  4. kourosh said

    is it possible to pass multiple parameter object to a query in ibatis.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: