急!!!在线等hibernate级联关系 外键为null
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.
说外键为空