日期:2014-05-18  浏览次数:20689 次

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 'f