急!!!在线等hibernate级联关系 外键为null

ttwhkl 2009-09-09 03:04:59
hibernate级联关系

如下配置strategy类
private Integer nmId;
private Set<TimesRule> timesRule ;

hbm.xml
<set name="TimesRule" inverse="true" cascade="all" >
<key column="nmStrategyId"/>
<one-to-many class="TimesRule"/>
</set>


timesRule类
private int nmId;
private int nmStrategyId;
private Strategy strategy;

hbm.xml
<many-to-one name="strategy" column="nmStrategyId" cascade="all" />


action类
HttpSession session = request.getSession();
TimesRule timesRule = new TimesRule();
timesRule.setDtEndDay(dtEndDay);
timesRule.setDtStartDay(dtStartDay);
timesRule.setStartTime(startTime);
timesRule.setEndTime(endTime);
timesRule.setBtIsInclude(btIsInclude);
timesRule.setTiType(tiType);
if (session.getAttribute("strategy") == null) {
strategy = new Strategy();
strategy.getTimesRule().add(timesRule);
session.setAttribute("strategy", strategy);

} else {
strategy = (Strategy) session.getAttribute("strategy");
strategy.getTimesRule().add(timesRule);
session.setAttribute("strategy", strategy);

}




public String saveStrag() throws Exception {
HttpSession session=request.getSession();
Strategy strategy = (Strategy) session.getAttribute("strategy");
if(getStragService().saveStrag(strategy)){
return SUCCESS;
}
return ERROR;
}


但是这样存储 报The column nmStrategyId in table tbTimesRule does not allow null values.
说外键为空
...全文
139 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ttwhkl 2009-09-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bearkin 的回复:]
不是  我的意思是timesRule 里应该有他多对一的 那一方的对象 你现在是strategy 里有 timesRule 而 timesRule 并没有持有 strategy  你的timesRule 里不是有个对象属性嘛
[/Quote]
哦 谢谢 明白了
BearKin 2009-09-09
  • 打赏
  • 举报
回复
不是 我的意思是timesRule 里应该有他多对一的 那一方的对象 你现在是strategy 里有 timesRule 而 timesRule 并没有持有 strategy 你的timesRule 里不是有个对象属性嘛
ttwhkl 2009-09-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bearkin 的回复:]
timesRule里面没有strategy 对象 你给他往里set个吧
[/Quote]
请问timesRule在哪里调用set方法
不修bux 2009-09-09
  • 打赏
  • 举报
回复
看不太懂
学习下
BearKin 2009-09-09
  • 打赏
  • 举报
回复
timesRule里面没有strategy 对象 你给他往里set个吧

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧