错误提示;
Hibernate: insert into T_CustomerInfo (mC_ID, cus_MC, cus_HY, cus_YW, cus_DZ, cus_FZR, cus_DH, cus_ZH, cus_LX, cus_RepR_ID, mcus_name, cus_RepR_Name, cus_pw) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
10:05:52,953  WARN JDBCExceptionReporter:100 - SQL Error: 515, SQLState: 23000
10:05:52,968 ERROR JDBCExceptionReporter:101 - 不能将值 NULL 插入列 'cus_ID',表 'crmdata.dbo.T_CustomerInfo';列不允许有 Null 值。INSERT 失败。
<bean id="companyInfoMg" class="com.oa.manager.impl.CompanyInfoMgImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>public void addEntC(CompanyInfo companyInfo) {

getHibernateTemplate().save(companyInfo);


}
companyInfoMg.addEntC(comInfo);
hibenate中也配置好了
通过调试comInfo获取到了值,可是执行后却显示如上错误!

解决方案 »

  1.   

    不能将值 NULL 插入列 'cus_ID'
    主键不能为空.
    应该是配置没写好把.hbm.xml贴出来看看
      

  2.   

    顶 配置文件里面设置为native就OK了..
      

  3.   

    <hibernate-mapping>
    <class table="T_CustomerInfo" name="com.oa.model.CompanyInfo">
        <id access="field" name="cus_ID" length="30">
          <generator class="native"/>
        </id>
        <property name="mC_ID" access="field" not-null="true"/>
        <property name="cus_MC" access="field" length="30"/>
        <property name="cus_HY" access="field" length="30"/>
        <property name="cus_YW" access="field" length="30"/>
        <property name="cus_DZ" access="field" length="30"/>
        <property name="cus_FZR" access="field" length="30"/>
        <property name="cus_DH" access="field" length="30"/>
        <property name="cus_ZH" access="field" length="30"/>
        <property name="cus_LX" access="field" length="30"/>
        <property name="cus_RepR_ID" access="field" length="30"/>
        <property name="mcus_name" access="field" length="30"/>
         <property name="cus_RepR_Name" access="field" length="30"/>
          <property name="cus_pw" access="field" length="30"/>
      </class>
      

  4.   


    <hibernate-mapping>
    <class table="T_CustomerInfo" name="com.oa.model.CompanyInfo">
        <id access="field" name="cus_ID" length="30">
          <generator class="native"/>
        </id>
        <property name="mC_ID" access="field" not-null="true"/>
        <property name="cus_MC" access="field" length="30"/>
        <property name="cus_HY" access="field" length="30"/>
        <property name="cus_YW" access="field" length="30"/>
        <property name="cus_DZ" access="field" length="30"/>
        <property name="cus_FZR" access="field" length="30"/>
        <property name="cus_DH" access="field" length="30"/>
        <property name="cus_ZH" access="field" length="30"/>
        <property name="cus_LX" access="field" length="30"/>
        <property name="cus_RepR_ID" access="field" length="30"/>
        <property name="mcus_name" access="field" length="30"/>
         <property name="cus_RepR_Name" access="field" length="30"/>
          <property name="cus_pw" access="field" length="30"/>
      </class>
      

  5.   

    是在持久化时报错了,数据库中将某些字段设置非空了,而你又插入null值肯定会报这种错误。
    所以你先检查要插入的数据是否符合数据的约束。
    若数据没有错误,就要检查配置文件了,但也并非楼上所说的缺少映射,缺少映射则会报另外的错误。
      

  6.   


    那个表没有设置约束,主要检测哪几个配置文件呀,
     <bean id="entAction" class="com.struts2.action.EntAction" scope="prototype">
         <!-- 公司信息 -->
            <property name="companyInfoMg" ref="companyInfoMg"></property><bean id="companyInfoMg" class="com.oa.manager.impl.CompanyInfoMgImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
      

  7.   

    你用的是什么数据库,你想让mC_ID自增吧。SQL Server的主键自增要自己配置的
      

  8.   


    sql2008  插入是数据都是通过页面上获取的 没有递增
      

  9.   

    首先检查实体映射文件和你的实体类的关系十分配的准确,其次,检查一下你的依赖注入关系十分准确(前提你用的是ssh集成),最后,检查一下,是否忘了加事物控制了。
      

  10.   

    有控制啊
     <action name="toAddEnt" class="entAction" method="toAddC">
             <result name="success">/entInfo/add_company.jsp</result>
            </action>
    <action name="addEntC" class="entAction" method="addEntC">
             <result name="success" type="chain">findEnts</result>
            </action>