ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chen, Tim" <Tim.C...@NielsenMedia.com>
Subject RE: Trying to N+1 and load a HashMap
Date Fri, 28 Apr 2006 13:51:32 GMT
Just curious Eric.
What happens when you comment out:

<result property="votes" resultMap="Stakeholder.votes"/>

It just seems weird the msg is asking you to check Stakeholder.votes.

-Tim 

-----Original Message-----
From: Eric Bauld [mailto:baulde@cpsc.ucalgary.ca] 
Sent: Thursday, April 27, 2006 6:28 PM
To: user-java@ibatis.apache.org
Subject: 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.executeQuery
WithCallback(GeneralStatement.java:188)
    at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
ForList(GeneralStatement.java:123)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
ExecutorDelegate.java:610)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
ExecutorDelegate.java:584)
    at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessi
onImpl.java:101)
    at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClient
Impl.java:78)
    at
rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81)
    at
test.rp.broker.TestStakeholderBroker.testGetStakeholders(TestStakeholder
Broker.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.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(RemoteTe
stRunner.java:478)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:344)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.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.setNestedResultMa
ppingValue(BasicResultMap.java:397)
    at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResult
Map(BasicResultMap.java:369)
    at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectVa
lues(BasicResultMap.java:355)
    at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResu
ltObject(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.sqlExecuteQu
ery(GeneralStatement.java:205)
    at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
WithCallback(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.setNestedResultMa
ppingValue(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.setNestedResultMa
ppingValue(BasicResultMap.java:397)
    at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResult
Map(BasicResultMap.java:369)
    at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectVa
lues(BasicResultMap.java:355)
    at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResu
ltObject(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.sqlExecuteQu
ery(GeneralStatement.java:205)
    at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
WithCallback(GeneralStatement.java:173)
    at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
ForList(GeneralStatement.java:123)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
ExecutorDelegate.java:610)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
ExecutorDelegate.java:584)
    at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessi
onImpl.java:101)
    at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClient
Impl.java:78)
    at
rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81)
    at
test.rp.broker.TestStakeholderBroker.testGetStakeholders(TestStakeholder
Broker.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.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(RemoteTe
stRunner.java:478)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:344)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.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.setNestedResultMa
ppingValue(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.setNestedResultMa
ppingValue(BasicResultMap.java:395)
    at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResult
Map(BasicResultMap.java:369)
    at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectVa
lues(BasicResultMap.java:355)
    at
com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResu
ltObject(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.sqlExecuteQu
ery(GeneralStatement.java:205)
    at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
WithCallback(GeneralStatement.java:173)
    at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
ForList(GeneralStatement.java:123)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
ExecutorDelegate.java:610)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
ExecutorDelegate.java:584)
    at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessi
onImpl.java:101)
    at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClient
Impl.java:78)
    at
rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81)
    at
test.rp.broker.TestStakeholderBroker.testGetStakeholders(TestStakeholder
Broker.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.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(RemoteTe
stRunner.java:478)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:344)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)





Mime
View raw message