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

ttwhkl ttwhkl 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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.
说外键为空
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
ttwhkl
Web 开发 81,108 成员 341,721 内容