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:
[code lang="xml"]
insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?);
[/code]
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.
No tag for this post.
{ 4 comments }
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?
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.
is it possible to pass multiple parameter object to a query in ibatis.
Comments on this entry are closed.