当前位置: 代码迷 >> J2EE >> 出的错误是:java.lang.IllegalArgumentException: argument type mismatch
  详细解决方案

出的错误是:java.lang.IllegalArgumentException: argument type mismatch

热度:146   发布时间:2016-04-22 02:54:58.0
hibernet的问题
出的错误是:java.lang.IllegalArgumentException: argument type mismatch
at org.yh.dlogic.FindCountDlogic.findCountByID(FindCountDlogic.java:39)
这个类FindCountDlogic的代码是
Java code
package org.yh.dlogic;import java.util.ArrayList;import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.cfg.Configuration;public class FindCountDlogic {    /**     * session定义     */    private Session session =null;        /**     * 构造函数     */    public FindCountDlogic() {        this.session =new Configuration().configure().            buildSessionFactory().openSession();    }        public List findCountByID (String countId) {                List countList = new ArrayList();        StringBuffer sb = new StringBuffer("from Count");                if (countId !=null && !"".equals(countId)) {            sb.append(" where countid = "+countId);        }                String sql = sb.toString();                Query query = this.session.createQuery(sql);                [color=#FF0000]countList = query.list();[/color]        return countList;        }}


出错的就是红色的那行

count类的xml文件如下
XML code
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!--     Mapping file autogenerated by MyEclipse Persistence Tools--><hibernate-mapping package="org.yh.vo">    <class name="org.yh.vo.Count" table="count" catalog="finances">        <id name="countid" type="java.lang.String">            <column name="countid" length="25" />            <generator class="assigned"></generator>        </id>        <property name="type" type="java.lang.String">            <column name="type" length="2" />        </property>        <property name="startMoney" type="java.lang.String">            <column name="startmoney" length="15" />        </property>        <property name="remainMoney" type="java.lang.String">            <column name="remainmoney" length="15" />        </property>        <property name="payMoney" type="java.lang.String">            <column name="paymoney" length="15" />        </property>        <set name="moneys" inverse="true" cascade="all">            <key column = "countid"></key>            <one-to-many class = "Money"/>        </set>    </class></hibernate-mapping>


大侠指点下啊,多谢

------解决方案--------------------
探讨
出错的就是红色的那行

------解决方案--------------------
大概是配置的问题,实体类的字段类型和表字段类型对不上。
------解决方案--------------------
String sql = sb.toString();
在这句后加一句
System.out.println("sql: " + sql);
调试,这样可以慢慢自己找答案
------解决方案--------------------
你先不要把List new 出来
 先让List countList = null;
然后 让 countList = query.list();
你试试这样行不行...
  相关解决方案