添加数据的时候,会报错:
2015-02-09 21:47:03 1,,SQL Error: 1452, SQLState: 23000 org.hibernate.util.JDBCExceptionReporterorg.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:100)
2015-02-09 21:47:03 1,,Cannot add or update a child row: a foreign key constraint fails (ischool
.ischool_shoop
, CONSTRAINT shoop_cityid
FOREIGN KEY (shoop_cityid
) REFERENCES ischool_ishequ_city_list
(cityid
) ON DELETE NO ACTION ON UPDATE NO ACTION) org.hibernate.util.JDBCExceptionReporterorg.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:101)
org.springframework.dao.DataIntegrityViolationException: could not insert: [com.revenueManager.entity.IschoolShoop]; SQL [insert into ischool.ischool_shoop (shoop_provinceId, shoop_typeid, shoop_cus_typeid, shoop_school_id, shoop_userid, shoop_districtId, shoop_title, shoop_secondTitle, shoop_titePic, shoop_content, shoop_fixedphone, shoop_phone, shoop_address, shoop_email, shoop_street, shoop_idcardPic, shoop_idcard, shoop_cus_name, shoop_licensePic, shoop_zipcode, shoop_note, shoop_checked, shoop_forbid, shoop_call_count, shoop_click_count, shoop_joinTime, shoop_endTime, shoop_comment_count, shoop_good_count, shoop_midile_count, shoop_bad_count, shoop_credits, shoop_level, shoop_istop, shoop_isshow, shoop_starts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.revenueManager.entity.IschoolShoop]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:637)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
at com.revenueManager.util.AbstractManager.save(AbstractManager.java:42)
at com.revenueManager.dao.impl.client.IschoolShoopDaoImp.addShoop(IschoolShoopDaoImp.java:54)
我写的时候表单数据是从相应外键表中获取的值,再通过选择的值查询,得到一个bean,如下
int provinceID = Integer.parseInt(getRequest().getParameter("province").toString());
IshequProvinceList province = provinceBiz.findByProvinceId(provinceID);
Shoop shop = new Shoop();
shop.setIschoolIshequProvinceList(province);
最后执行增加
int flag = shoopBiz.addShoop(shop);
我已经检查很多次,shop表的数据除了主键是自增的,没设置有值,其他的都设置了值。
求解决。