兔子飞机 2015-02-09 14:16 采纳率: 50%
浏览 2066
已采纳

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表的数据除了主键是自增的,没设置有值,其他的都设置了值。
求解决。

  • 写回答

1条回答 默认 最新

  • ligang819350766 2015-02-10 01:04
    关注

    ischool_ishequ_city_list (cityid) 仔细看看数据库

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 VB.NET如何绘制倾斜的椭圆