ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shepherdz <zhaoxin...@ndtech.com.cn>
Subject Can I use Map or XML result in mapping complex properties
Date Mon, 22 May 2006 05:48:15 GMT

Our project needs to use generic result structure to recieve results of a
query, i.e. Map or XML. How can I use Map or XML result in mapping complex
properties? 
 
Following is a sample mapping file I write.
 
<sqlMap namespace="User">
  <resultMap id="interestGroupResult" class="java.util.HashMap"
groupBy="id">
    <result property="id" column="GroupID"/>
    <result property="name" column="GroupName"/>
    <result property="description" column="GroupDesp"/>
    <result property="interests" resultMap="User.interestsResult"/>
  </resultMap>
  <resultMap id="interestsResult" class="java.util.HashMap" groupBy="id">
    <result property="id" column="InterestID"/>
    <result property="name" column="InterestName"/>
    <result property="description" column="InterestDesp"/>
    <result property="users" resultMap="User.userResult"/>
  </resultMap>
  <resultMap id="userResult" class="java.util.HashMap">
    <result property="id" column="UserID"/>
    <result property="name" column="UserName"/>
    <result property="password" column="UserPassword"/>
    <result property="firstName" column="UserFirstName"/>
    <result property="middleName" column="UserMiddleName"/>
    <result property="lastName" column="UserLastName"/>
    <result property="age" column="UserAge"/>
    <result property="affiliation" column="UserAffiliation"/>
    <result property="email" column="UserEmail"/>
    <result property="telephone" column="UserTelephone"/>
    <result property="mobile" column="UserMobile"/>
  </resultMap>
  <select id="showGroupUser" parameterClass="java.lang.String"
resultMap="interestGroupResult">
    SELECT G.ID as GroupID, G.Name as GroupName, G.Description as GroupDesp,
    I.ID as InterestID, I.Name as InterestName, I.Description as
InterestDesp,
    U.ID as UserID, U.Name as UserName, U.Password as UserPassword,
U.FirstName as UserFirstName, U.MiddleName as UserMiddleName, 
    U.LastName as UserLastName, U.Age as UserAge, U.Affiliation as
UserAffiliation, U.Email as UserEmail, U.Telephone as UserTelephone, 
    U.Mobile as UserMobile
    FROM UserInterestsGroup G
    LEFT OUTER JOIN UserInterest I ON I.InterestGroup = G.ID
    LEFT OUTER JOIN Users U ON U.Interest = I.ID
    WHERE G.ID = #value#
 </select>
</sqlMap>
 
However, an exception is thrown: 
"com.ibatis.sqlmap.client.SqlMapException: Error instantiating collection
property for mapping 'interests'.  Cause: java.lang.ClassCastException:
java.lang.Object"
 
Is my mapping statement invalid? Or the iBatis does not allow mapping Map or
XML as collection propery? 

--
View this message in context: http://www.nabble.com/Can+I+use+Map+or+XML+result+in+mapping+complex+properties-t1661124.html#a4500363
Sent from the iBATIS - User - Java forum at Nabble.com.


Mime
View raw message