s2sh mysql 数据库中 将img字段(varchar)设置为 允许为空。XXX.hbm.xml中也如下处理:
<property name="img" column="img" type="string" not-null="false"></property>
我在Action中做插入操作。
我是获得一个A对象的然后把A对象的值set到B对象中。
最后保存B。
由于A中没有img属性。业务上也不必要。(我这个img是插入成功后用户自己手动上传图片即可,所以在插入内容时就没有设置)
我没有B.setImg()这样的设置。
执行插入操作 打出如下信息:
Hibernate: insert into qcn_index_recomm (img, play_type, lid, state, effective_start, effective_end, create_time, display_order, link) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
10:29:21,119  WARN JDBCExceptionReporter:77 - SQL Error: 1048, SQLState: 23000
10:29:21,119 ERROR JDBCExceptionReporter:78 - Column 'img' cannot be null
求解释这是为什么

解决方案 »

  1.   

    我没有B.setImg()这样的设置。
    不是说我po中没有set/get方法。我是指在插入操作也就是 A的值set给B的时候我没有 setImg的值
      

  2.   

    新建的时候指定字段jdbcType=VARCHAR试试,我用mybatis也遇到过这种问题,加上就没问题了
      

  3.   

    insert into qcn_index_recomm (img, play_type, lid, state, effective_start, effective_end, create_time, display_order, link) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
    直接拷贝到工具里试试这条SQL运行的起不,
      

  4.   

    字段可为空的话,设置的时候 可以如下
    <property name="img" column="img" type="string"></property>  不要 not-null="false",
    我一般是这样设的,都没问题,用 hibernate自带的方法插入一般不会出错呀,你再仔细看看是哪的问题
      

  5.   

    第一看下你的映射文件是否如楼上所讲的那样..
    第二你看下数据库的那个img字段是否有默认值 是否允许为null