程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> shh-hibernat,有一個外鍵關系的表添加不了數據

shh-hibernat,有一個外鍵關系的表添加不了數據

編輯:編程綜合問答
hibernat,有一個外鍵關系的表添加不了數據

添加數據的時候,會報錯:

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) 仔細看看數據庫

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved