错误提示;
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获取到了值,可是执行后却显示如上错误!
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获取到了值,可是执行后却显示如上错误!
主键不能为空.
应该是配置没写好把.hbm.xml贴出来看看
<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>
<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>
所以你先检查要插入的数据是否符合数据的约束。
若数据没有错误,就要检查配置文件了,但也并非楼上所说的缺少映射,缺少映射则会报另外的错误。
那个表没有设置约束,主要检测哪几个配置文件呀,
<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>
sql2008 插入是数据都是通过页面上获取的 没有递增
<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>