3
我對iBatis(今天開始)相當陌生,我試圖查詢我的數據庫中的對象列表(返回單個對象和值工作正常)。iBatis - 加載對象列表
我正在關注THIS教程(幾乎沒有任何修改 - 我的課程名稱不同)。你能告訴我在這種情況下我做錯了什麼嗎?
這是我獲得的用戶列表映射:
<!-- Retrieve all users -->
<select id="getAll" resultClass="wa.myslima.refman.entities.User">
SELECT * FROM USER
</select>
當調用
rd = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient smc = SqlMapClientBuilder.buildSqlMapClient(rd);
users = (List<User>) smc.queryForList("User.getAll", null);
我得到以下異常:
--- The error occurred in User.xml.
--- The error occurred while applying a result map.
--- Check the User.getAll-AutoResultMap.
--- The error occured while instantiating the result object
--- Cause: java.lang.RuntimeException: JavaBeansDataExchange could not instantiate result class. Cause: java.lang.InstantiationException: wa.myslima.refman.entities.User
在其他一些教程,他們使用一些額外的映射,所以我也試過這種方法沒有成功:
<resultMap id="UserResult" class="wa.myslima.entities.User">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="email" column="email"/>
</resultMap>
<select id="getAll" resultMap="UserResult">
select * from USER
</select>
感謝您的任何提示。這可能是一些愚蠢的錯誤一樣錯字,但我仍然無法看到它通過......
編輯:User.java
import java.io.Serializable;
public class User implements Serializable {
private static final long serialVersionUID = 1456239434165308496L;
private int id;
private String name;
private String password;
private String email;
public User(String name, String password, String email) {
this.name = name;
this.password = password;
this.email = email;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
}
粘貼您的用戶類。 – SMA
@SMA有它。 – Smajl