<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMapConfig      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"><sqlMapConfig>  <transactionManager type="JDBC" commitRequired="false">
    <dataSource type="SIMPLE">
      <property name="JDBC.Driver" value="net.sourceforge.jtds.jdbc.Driver"/>
      <property name="JDBC.ConnectionURL" value="jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=test"/>
      <property name="JDBC.Username" value="sa"/>
      <property name="JDBC.Password" value="sa"/>
    </dataSource>
  </transactionManager>  <sqlMap resource="tao/ibatis/bean/User.hbm.xml"/></sqlMapConfig><?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="tao.ibatis.bean.User"/>
  
  <resultMap id="UserResult" class="User">
   <result property="id" column="id"/>
    <result property="username" column="username"/>
    <result property="password" column="password"/>
  </resultMap>  <select id="selectAllUsers" resultMap="UserResult">
    select count(*) from "user"
  </select>   
</sqlMap>
package tao.ibatis.bean;import java.io.Serializable;public class User implements Serializable{
private long id;
private String username;
private String password;

public User(){

}

public long getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package tao.ibatis.test;import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;
import com.mydomain.domain.Account;import java.io.Reader;
import java.io.IOException;
import java.util.List;
import java.sql.SQLException;public class UserTest {  private static SqlMapClient sqlMapper;  static {
    try {
      Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
      sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
      reader.close(); 
    } catch (IOException e) {
      throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
    }
  }  public static List selectAllUsers () throws SQLException {
    return sqlMapper.queryForList("selectAllUsers");
  }
  public static void main(String[] args) throws SQLException {
List<?> ls = selectAllUsers();
System.out.println(ls.size());
}
}请问大家 我该怎么办呢? 
Exception in thread "main" com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in tao/ibatis/bean/User.hbm.xml.  
--- The error occurred while applying a result map.  
--- Check the User.UserResult.  
--- Check the result mapping for the 'id' property.  
--- Cause: java.sql.SQLException: Invalid column name id.
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:122)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:98)
at tao.ibatis.test.UserTest.selectAllUsers(UserTest.java:28)
at tao.ibatis.test.UserTest.main(UserTest.java:48)
Caused by: java.sql.SQLException: Invalid column name id.

解决方案 »

  1.   

    数据库表里有id吗?还有long改成int统一一下
      

  2.   

    楼主主键的类型一般不推介使用long型...换个其他类型....long型在框架里转换还是很麻烦的....
      

  3.   

      <resultMap id="UserResult" class="User">
      <result property="id" column="id"/>
      <result property="username" column="username"/>
      <result property="password" column="password"/>
      </resultMap>  <select id="selectAllUsers" resultMap="UserResult">
      select count(*) from "user"
      </select>
    问题解决了  我是没有搞明白  resultMap的含义  
    resultMap="UserResult" 中 指定了 返回类型而我返回的count(*) 却 没有与其关联
      <resultMap id="UserResult" class="User">
      <result property="id" column="id"/>
     
      </resultMap>  <select id="selectAllUsers" resultMap="UserResult">
      select count(*) as id from "user"
      </select>这样子 搞定了