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 Eric Bauld <ba...@cpsc.ucalgary.ca> on 2006/04/28 00:28:27 UTC
Trying to N+1 and load a HashMap
I have a list of stakeholders, and I want to load all of the weights
into a map with the requirementId as a key.
I am getting the following error and cannot figure out why. What do I
have wrong in the weights mapping ? I want the map to be key/value pair
of requirementId/rp.object.baseImpl.BasicWeight. Im confused at to how
the Hashmap will load the value properly, if it worked at this point.
SQLMAP
<sqlMap namespace="Stakeholder">
<resultMap id="weights" class="java.util.HashMap">
<result property="id" column="requirementId"/>
<result property="weight" column="groupWeight"/>
<result property="requirementId" column="requirementId"/>
</resultMap>
<resultMap id="votes" class="rp.object.baseImpl.BasicVote">
<result property="userId" column="userId" />
<result property="instanceId" column="instanceId"/>
<result property="requirementId" column="requirementId"/>
<result property="criteriaId" column="criteriaId"/>
<result property="voteValue" column="voteValue"/>
</resultMap>
<resultMap id="stakeMap" class="rp.object.baseImpl.BasicStakeholder"
groupBy="databaseId">
<result property="databaseId" column="userId"/>
<result property="weight" column="weight"/>
<result property="loginId" column="loginId"/>
<result property="email" column="email"/>
<result property="company" column="company"/>
<result property="department" column="department"/>
<result property="lastLogon" column="lastLogon"/>
<result property="logonCount" column="logonCount"/>
<result property="votes" resultMap="Stakeholder.votes"/>
<result property="weights" resultMap="Stakeholder.weights"/>
</resultMap>
<select id="getStakeholders" resultMap="stakeMap">
SELECT uw.weight AS weight,
v.user_id AS userId,
u.login_id AS loginId,
u.email AS email,
u.company AS company,
u.department AS department,
u.last_logon AS lastLogon,
u.logon_count AS logonCount,
i.instance_id AS instanceId,
v.requirement_id AS requirementId,
v.criteria_id AS criteriaId,
v.value AS voteValue,
gw.weight AS groupWeight
FROM vote v, user_weight uw, instance i, user u,
requirement r LEFT JOIN user_group_weight gw
ON r.requirement_folder_id = gw.requirement_folder_id
AND uw.user_id = gw.user_id
WHERE i.instance_id = 1
AND v.user_id = u.user_id
AND v.requirement_id = r.requirement_id
AND i.instance_id = v.instance_id
AND uw.user_id = u.user_id
AND uw.instance_id = i.instance_id
AND i.instance_id = uw.instance_id
</select>
</sqlMap>
And my error Trace
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in config/maps/stakeholder.xml.
--- The error occurred while applying a result map.
--- Check the Stakeholder.votes.
--- The error happened while setting a property on the result object.
--- Cause: com.ibatis.sqlmap.client.SqlMapException: Error instantiating
collection property for mapping 'weights'. Cause:
java.lang.InstantiationException: java.util.Map
Caused by: java.lang.InstantiationException: java.util.Map
Caused by: com.ibatis.sqlmap.client.SqlMapException: Error instantiating
collection property for mapping 'weights'. Cause:
java.lang.InstantiationException: java.util.Map
Caused by: java.lang.InstantiationException: java.util.Map
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
at
rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81)
at
test.rp.broker.TestStakeholderBroker.testGetStakeholders(TestStakeholderBroker.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.ibatis.sqlmap.client.SqlMapException: Error instantiating
collection property for mapping 'weights'. Cause:
java.lang.InstantiationException: java.util.Map
Caused by: java.lang.InstantiationException: java.util.Map
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:397)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultMap(BasicResultMap.java:369)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:355)
at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:63)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:395)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 22 more
Caused by: java.lang.InstantiationException: java.util.Map
at java.lang.Class.newInstance0(Class.java:293)
at java.lang.Class.newInstance(Class.java:261)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:395)
... 29 more
Caused by:
com.ibatis.sqlmap.client.SqlMapException: Error instantiating collection
property for mapping 'weights'. Cause:
java.lang.InstantiationException: java.util.Map
Caused by: java.lang.InstantiationException: java.util.Map
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:397)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultMap(BasicResultMap.java:369)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:355)
at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:63)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:395)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
at
rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81)
at
test.rp.broker.TestStakeholderBroker.testGetStakeholders(TestStakeholderBroker.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.InstantiationException: java.util.Map
at java.lang.Class.newInstance0(Class.java:293)
at java.lang.Class.newInstance(Class.java:261)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:395)
... 29 more
Caused by:
java.lang.InstantiationException: java.util.Map
at java.lang.Class.newInstance0(Class.java:293)
at java.lang.Class.newInstance(Class.java:261)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:395)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultMap(BasicResultMap.java:369)
at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:355)
at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:63)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:395)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
at
rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81)
at
test.rp.broker.TestStakeholderBroker.testGetStakeholders(TestStakeholderBroker.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)