iBatis 中一对多时要注意的问题

出现的问题:

2006-08-25 16:41:40 [com.opensymphony.oscache.base.Config]-[DEBUG] Config() called
2006-08-25 16:41:40 [com.opensymphony.oscache.base.Config]-[DEBUG] Getting Config
2006-08-25 16:41:40 [com.opensymphony.oscache.base.Config]-[INFO] Properties {cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache, cache.capacity=1000, cache.memory=true, cache.event.listeners=com.opensymphony.oscache.extra.ScopeEventListenerImpl}
2006-08-25 16:41:40 [com.opensymphony.oscache.base.AbstractCacheAdministrator]-[DEBUG] Constructed AbstractCacheAdministrator()
2006-08-25 16:41:40 [com.opensymphony.oscache.general.GeneralCacheAdministrator]-[INFO] Constructed GeneralCacheAdministrator()
2006-08-25 16:41:40 [com.opensymphony.oscache.general.GeneralCacheAdministrator]-[INFO] Creating new cache
2006-08-25 16:41:40 [java.sql.Connection]-[DEBUG] {conn-100000} Connection
2006-08-25 16:41:41 [java.sql.PreparedStatement]-[DEBUG] {pstm-100001} PreparedStatement:    select id,name,sex from user where id=? 
2006-08-25 16:41:41 [java.sql.PreparedStatement]-[DEBUG] {pstm-100001} Parameters: [1]
2006-08-25 16:41:41 [java.sql.PreparedStatement]-[DEBUG] {pstm-100001} Types: [java.lang.String]
2006-08-25 16:41:41 [java.sql.ResultSet]-[DEBUG] {rset-100002} ResultSet
2006-08-25 16:41:41 [java.sql.ResultSet]-[DEBUG] {rset-100002} Header: [id, name, sex, id]
2006-08-25 16:41:41 [java.sql.ResultSet]-[DEBUG] {rset-100002} Result: [1, anna li, 5, 1]
com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/ibatis/demo/sqlmap/map/User.xml. 
--- The error occurred while applying a result map. 
--- Check the User.get-user-result. 
--- The error happened while setting a property on the result object. 
--- Cause: com.ibatis.common.exception.NestedRuntimeException: Error setting properties of 'com.ibatis.demo.User@116ab4e'.  Cause: java.lang.IllegalArgumentException: argument type mismatch
Caused by: java.lang.IllegalArgumentException: argument type mismatch
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error setting properties of 'com.ibatis.demo.User@116ab4e'.  Cause: java.lang.IllegalArgumentException: argument type mismatch
Caused by: java.lang.IllegalArgumentException: argument type mismatch
 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 com.ibatis.demo.UserDao.getUsers(UserDao.java:92)
 at com.ibatis.demo.UserDao.main(UserDao.java:144)
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error setting properties of 'com.ibatis.demo.User@116ab4e'.  Cause: java.lang.IllegalArgumentException: argument type mismatch
Caused by: java.lang.IllegalArgumentException: argument type mismatch
 at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:51)
 at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112)
 at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:346)
 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)
 ... 7 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
 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:585)
 at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:45)
 ... 14 more

package com.ibatis.demo;

import java.io.Serializable;
import java.util.ArrayList;
//import java.util.HashSet;
import java.util.List;
//import java.util.Set;

public class User implements Serializable{

 /**
  *
  */
 private Integer id;
 private String name;
 private Integer sex;
 private List addresses = new ArrayList();
 //iBatis2.0 仅对java.util.List或java.util.Collection类型进行支持。
 //原文:(载自:iBatis SQLMap2-cn.pdf文档)唯一的不同是,让SQL Map架构装入复杂类型集合(List)的业务对象的属性必须是java.util.List或java.util.Collection类型
 //private Set addresses = new HashSet();
 public User(){
 }
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Integer getSex() {
  return sex;
 }
 public void setSex(Integer sex) {
  this.sex = sex;
 }
// public Set getAddresses() {
//  return addresses;
// }
// public void setAddresses(Set addresses) {
//  this.addresses = addresses;
// }
 public void setAddresses(List addresses) {
  this.addresses = addresses;
 }
 public List getAddresses() {
  return addresses;
 }
 
}

 

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="User">
 <typeAlias alias="user" type="com.ibatis.demo.User" />
 <typeAlias alias="string" type="java.lang.String" />
 <typeAlias alias="address" type="com.ibatis.demo.Address"/>
 <cacheModel id="userCache" type="OSCACHE">
  <flushInterval hours="24" />
  <flushOnExecute statement="updateUser" />
  <flushOnExecute statement="insertUser" />
  <flushOnExecute statement="delUser" />
  <flushOnExecute statement="deleteUser" />
  <property name="size" value="1000" />
 </cacheModel>
 <resultMap id="get-user-result" class="user">
  <result property="id" column="id"/>
  <result property="name" column="name"/>
  <result property="sex" column="sex"/>
  <result property="addresses" column="id" select="getAddressByUserId"/>
 </resultMap>
 <resultMap id="get-address-result" class="address">
  <!-- result property="userid" column="userid"/-->
  <result property="address" column="address"/>
  <result property="zipcode" column="zipcode"/>
 </resultMap>
 <select id="getUsers" parameterClass="string" resultMap="get-user-result">
  select id,name,sex from user where id=#id#
 </select>
 <select id="getAddressByUserId" parameterClass="int" resultMap="get-address-result">
  select address,zipcode from address where userid = #id#
 </select>
 
 <select id="getUser" parameterClass="string" cacheModel="userCache"
  resultClass="user">
  select name,sex from user where name=#name#
 </select>
 <update id="updateUser" parameterClass="user">
  update user set name=#name#, sex=#sex# where id=#id#
 </update>
 <insert id="insertUser" parameterClass="user">
  insert into user( name,sex) values(#name#,#sex#)
 </insert>
 <delete id="deleteUser" parameterClass="string">
  delete from user where id=#id#
 </delete>
 <delete id="delUser" parameterClass="user">
  delete from user where id=#id#
 </delete>
 <select id="getUserList" parameterClass="string"
  cacheModel="userCache" resultClass="user">
  select id ,name,sex from user where name like #name#
 </select>
</sqlMap>

 

你可能感兴趣的:(properties,String,ibatis,user,Integer,delete)