Commontop.xml
<set name="pouringgirder" lazy="false" cascade="all">
<key>
<column name="ct_id" not-null="false"></column>
</key>
<one-to-many class="com.zjrd.entity.Pouringgirder"/>
</set>Pouringgirder.xml
<many-to-one name="commontop" class="com.zjrd.entity.Commontop" fetch="select" not-found="ignore" insert="false" update="false">
<column name="ct_id" not-null="true" ></column>
</many-to-one>delete.action
public String deleteCommontop(){
int id=Integer.parseInt(request.getParameter("id"));
this.cmtBiz.deleteCommontop(id);
return "delete";
}关联id保存在多的一方Pouringgirder表中,并且是非空。然后运行,直接报错:
严重: Servlet.service() for servlet default threw exception
com.microsoft.sqlserver.jdbc.SQLServerException: 不能将值 NULL 插入列 'ct_id',表 'Bridge.dbo.pouringgirder';列不允许有空值。UPDATE 失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
...
由报错信息,我觉得是删除操作并不是在删除一表的时候直接删除关联多表,而是把多表的关联id改为null了,关联多表还是存在的,然后我想要的是在删除一表的时候,直接删除与之相关联的多表。
上网搜了一遍后,只找到了一个答案,在一表配置文件的<set>内加入inverse="true",交出主控权,再次运行之后,功能实现了,但是再次报错:
严重: Servlet.service() for servlet default threw exception
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at com.zjrd.action.CommontopAction.findCommontopById(CommontopAction.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
对此,十分费解,思路完全串不起来,求高手解惑,或者指点下正确的功能实现方法。
想要的结果:级联删除,删除一,直接关联删除多!
解决方案 »
- Hibernate日期数据绑定的问题
- 关于struts 的一个 form 问题
- 请问是什么原因?谢谢
- structs配置数据源
- 谁能提供一些struts入门的教程!最好是视频的!谢谢!
- 〈〈JSF第一步--JSF+Spring+Hibernate+AJAX编程实践〉〉终于面世,希望能对初学者有些实际的帮助
- webservices缓存问题如何解决?
- 【紧急求助】resin不解析jsp页面中taglib
- properties.out 问题
- 数据库里取出的整数 我想除以100 保留两位小数 结果定义为什么类型啊
- 转换 varchar 值 '010102010101' 时溢出了整数列。超过了其中最大的整数值。
- 登录jsp页面为什么无法登录?
不过还是想问,为什么加上inverse= "true "能解决第一个异常?
没人接分吗?
删除Commontop时,Commontop对应的Pouringgirder所关联的Commontop就不存在了。
而Commontop要维护关系,所以就修改外键为空。而外键被设置为not nul.