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 "Blackburn, Gary (HHS/RHRC)" <Ga...@hhs.gov> on 2006/05/30 18:05:30 UTC
Problem Converting Inline Parameters to Parameter Map
Hi all. I'm having trouble converting some (working) inline parameters
to the equivalent parameter map.
This works just fine:
<select id="getemployeeMasters" resultClass="org.model.employeeMaster">
SELECT substr(administrative_code, 1, 3) as org
FROM administrative_code a, employeeMaster e
WHERE rtrim(a.administrative_code) = rtrim(e.org)
AND a.administrative_code like #org#
GROUP BY substr(administrative_code, 1, 3)
</select>
This does not:
<parameterMap id="getemployeeMastersParam"
class="org.model.employeeMaster">
<parameter property="org" />
</parameterMap>
<select id="getemployeeMasters" parameterMap="getemployeeMastersParam">
SELECT substr(administrative_code, 1, 3) as org
FROM administrative_code a, employeeMaster e
WHERE rtrim(a.administrative_code) = rtrim(e.org)
AND a.administrative_code like ?
GROUP BY substr(administrative_code, 1, 3)
</select>
I get the following error:
WARN - CommonsLoggingOutput.warn(44) | Erroring: id[510_1149004528570]
message[org.springframework.jdbc.UncategorizedSQLException:
(SqlMapClient operation): encountered SQLException [
--- The error occurred in org/dao/ibatis/employeeMasterSQL.xml.
--- The error occurred while preparing the mapped statement for
execution.
--- Check the getemployeeMasters.
--- Cause: java.sql.SQLException: Invalid parameter object type.
Expected 'org.model.employeeMaster' but found 'java.lang.String'.];
nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in org/dao/ibatis/employeeMasterSQL.xml.
--- The error occurred while preparing the mapped statement for
execution.
--- Check the getemployeeMasters.
--- Cause: java.sql.SQLException: Invalid parameter object type.
Expected 'org.model.employeeMaster' but found 'java.lang.String'.
>From what I can tell these two versions should be functionally
equivalent but obviously they are not. (I need to convert to a parameter
map so that I can turn on caching.)
Any help would be appreciated! :-)
--
Gary Blackburn
Re: Problem Converting Inline Parameters to Parameter Map
Posted by Jeff Butler <je...@gmail.com>.
I suspect that the problem is in the code that calls this statement - you
need to do this:
employeeMaster em = new employeeMaster();
em.setOrg("someorg");
sqlMap.queryForList("getEmployeeMasters", em);
Your calling code is probably still passing in a String for #org# for the
previous version of the sql map like this:
sqlMap.queryForList("getEmployeeMasters",
"someorg");
Two other comments:
1. By convention, Java classes whould start with upper case letters
(EmployeeMaster rather than employeeMaster)
2. I don't understand what you think the the link is between parameter maps
and caching. We use caching a lot and never use a parameter map. I think
you only need to use parameter maps with stored procedures.
Jeff Butler
On 5/30/06, Blackburn, Gary (HHS/RHRC) <Ga...@hhs.gov> wrote:
>
> Hi all. I'm having trouble converting some (working) inline parameters
> to the equivalent parameter map.
>
> This works just fine:
>
> <select id="getemployeeMasters" resultClass="org.model.employeeMaster">
> SELECT substr(administrative_code, 1, 3) as org
> FROM administrative_code a, employeeMaster e
> WHERE rtrim(a.administrative_code) = rtrim(e.org)
> AND a.administrative_code like #org#
> GROUP BY substr(administrative_code, 1, 3)
> </select>
>
> This does not:
>
> <parameterMap id="getemployeeMastersParam" class="org.model.
> employeeMaster">
> <parameter property="org" />
> </parameterMap>
>
> <select id="getemployeeMasters" parameterMap="getemployeeMastersParam">
> SELECT substr(administrative_code, 1, 3) as org
> FROM administrative_code a, employeeMaster e
> WHERE rtrim(a.administrative_code) = rtrim(e.org)
> AND a.administrative_code like ?
> GROUP BY substr(administrative_code, 1, 3)
> </select>
>
> I get the following error:
>
> WARN - CommonsLoggingOutput.warn(44) | Erroring: id[510_1149004528570]
> message[org.springframework.jdbc.UncategorizedSQLException: (SqlMapClient
> operation): encountered SQLException [
> --- The error occurred in org/dao/ibatis/employeeMasterSQL.xml.
> --- The error occurred while preparing the mapped statement for
> execution.
> --- Check the getemployeeMasters.
> --- Cause: java.sql.SQLException: Invalid parameter object type. Expected
> 'org.model.employeeMaster' but found 'java.lang.String'.]; nested
> exception is com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in org/dao/ibatis/employeeMasterSQL.xml.
> --- The error occurred while preparing the mapped statement for
> execution.
> --- Check the getemployeeMasters.
> --- Cause: java.sql.SQLException: Invalid parameter object type. Expected
> 'org.model.employeeMaster' but found 'java.lang.String'.
>
>
> From what I can tell these two versions should be functionally
> equivalent but obviously they are not. (I need to convert to a parameter map
> so that I can turn on caching.)
>
> Any help would be appreciated! :-)
>
> --
> Gary Blackburn
>
Re: Problem Converting Inline Parameters to Parameter Map
Posted by Larry Meadors <lm...@apache.org>.
Looks like the parameter being passed in is a String instead of an
org.model.employeeMaster instance (that should be EmployeeMaster,
btw).
Also, the first version has a parameter map as well, it is just
created dynamically, so it should cache just fine if you define a
cache model, and add a cacheModel attribute to the select tag.
Larry
On 5/30/06, Blackburn, Gary (HHS/RHRC) <Ga...@hhs.gov> wrote:
>
>
> Hi all. I'm having trouble converting some (working) inline parameters to
> the equivalent parameter map.
>
> This works just fine:
>
>
> <select id="getemployeeMasters" resultClass="org.model.employeeMaster">
> SELECT substr(administrative_code, 1, 3) as org
> FROM administrative_code a, employeeMaster e
> WHERE rtrim(a.administrative_code) = rtrim(e.org)
> AND a.administrative_code like #org#
> GROUP BY substr(administrative_code, 1, 3)
> </select>
>
> This does not:
>
> <parameterMap id="getemployeeMastersParam" class="org.model.employeeMaster">
> <parameter property="org" />
> </parameterMap>
>
> <select id="getemployeeMasters"
> parameterMap="getemployeeMastersParam">
> SELECT substr(administrative_code, 1, 3) as org
> FROM administrative_code a, employeeMaster e
> WHERE rtrim(a.administrative_code) = rtrim(e.org)
> AND a.administrative_code like ?
> GROUP BY substr(administrative_code, 1, 3)
> </select>
>
> I get the following error:
>
> WARN - CommonsLoggingOutput.warn(44) | Erroring: id[510_1149004528570]
> message[org.springframework.jdbc.UncategorizedSQLException:
> (SqlMapClient operation): encountered SQLException [
> --- The error occurred in
> org/dao/ibatis/employeeMasterSQL.xml.
> --- The error occurred while preparing the mapped statement for execution.
> --- Check the getemployeeMasters.
> --- Cause: java.sql.SQLException: Invalid parameter object type. Expected
> 'org.model.employeeMaster' but found 'java.lang.String'.]; nested exception
> is com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in
> org/dao/ibatis/employeeMasterSQL.xml.
> --- The error occurred while preparing the mapped statement for execution.
> --- Check the getemployeeMasters.
> --- Cause: java.sql.SQLException: Invalid parameter object type. Expected
> 'org.model.employeeMaster' but found 'java.lang.String'.
>
>
> From what I can tell these two versions should be functionally equivalent
> but obviously they are not. (I need to convert to a parameter map so that I
> can turn on caching.)
>
> Any help would be appreciated! :-)
>
> --
>
> Gary Blackburn