添加數據的時候,會報錯:
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表的數據除了主鍵是自增的,沒設置有值,其他的都設置了值。
求解決。
ischool_ishequ_city_list (cityid) 仔細看看數據庫