MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » Unknown column 'bsname' in 'field list'解决方法

Unknown column 'bsname' in 'field list'解决方法

www.MyException.Cn  网友分享于:2013-04-09  浏览:1472次
Unknown column 'bsname' in 'field list'
项目中用struts来进行前台设计,其中对一个表单的添加修改操作,都用在一个action中,action如下:
Java code

AccountTable account = (AccountTable) request.getSession()
        .getAttribute("accountInfo");
        flag = crmDao.getBusinessByName((String) f.get("bsname"),account);
        JzBusiness business = null;
        String bsid = request.getParameter("bsid");
        if (bsid != null) {
            business = crmDao.getJzBusiness(bsid);
            boolean s = !business.getBsname().equals((String) f.get("bsname"));
            if (!business.getBsname().equals((String) f.get("bsname"))) {
                if (flag) {
                    request.setAttribute("errormessage", "业务已经存在!");
                    return mapping.findForward("businessexit");
                }
            }
        } else {
            if (flag) {
                request.setAttribute("errormessage", "业务已经存在!");
                return mapping.findForward("businessexit");
            }
            business = new JzBusiness();
        }
        business.setBsname((String) f.get("bsname"));
        business.setComments((String) f.get("comment"));
        int type = Integer.parseInt((String) f.get("remindtype"));
        business.setRemindtype(type);
        business.setAccountTable(account);
        crmDao.addBusiness(business);


hibernate的映射文件如下:
Java code

<hibernate-mapping>
    <class name="cn.qdrk.strive.model.JzBusiness" table="jz_business">
        <cache usage="read-write"/>
        <id name="bsId" type="java.lang.Integer">
            <column name="bs_id" />
            <generator class="native"></generator>
        </id>
        <many-to-one name="accountTable" class="cn.qdrk.strive.model.AccountTable" fetch="select">
            <column name="account_id" />
        </many-to-one>
        <property name="bsname" type="java.lang.String">
            <column name="bsname" length="150" not-null="true" />
        </property>
        <property name="comments" type="java.lang.String">
            <column name="comments" length="200" />
        </property>
        <property name="remindtype" type="java.lang.Integer">
            <column name="remindtype" />
        </property>
        <set name="jzKmessages" inverse="true">
            <key>
                <column name="bs_id" />
            </key>
            <one-to-many class="cn.qdrk.strive.model.JzKmessage" />
        </set>
    </class>
</hibernate-mapping>


这个添加,删除都可以,但是当进行编辑操作的时候,也能拿到String bsid = request.getParameter("bsid");但是提交的时候就会报:
Java code

Caused by: 
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: Unknown column 'bsname' in 'field list'
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)


但是我查看映射文件以及数据库中的字段都有bsname,form表单中也有,在google上搜索有说是找不到id的,可是我能够拿到要编辑的id,大家帮我看看。

------解决方案--------------------

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有