急!!!在线等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.
说外键为空
如下配置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.
说外键为空
...全文
相关推荐
Hibernate使用外键ForeignKey
Hibernate使用外键的一个简单直接的例子,便于学习者很好地理解 DB 的配置操作
30、深入理解Hibernate:对象关系映射与高级特性
本文深入探讨了Hibernate框架的核心特性与高级应用,涵盖对象关系映射(ORM)的基本原理、数据库配置、会话管理、查询语言(HQL)、多值关联、组件映射、缓存机制、批处理优化、数据访问层设计等内容。此外,还介绍了懒加载与视图中打开会话模式、自定义映射类型、数据过滤器以及事务管理的最佳实践。通过这些技术,开发者可以高效地进行数据持久化管理,并提升应用程序的性能和可维护性。
hibernate外键实现一对一单向关联关系源码
hibernate外键实现一对一单向关联关系源码
Hibernate Annotation 基于外键的一对多双向关联
NULL 博文链接:https://paladin1988.iteye.com/blog/1657564
Hibernate一对一外键映射
Hibernate一对一外键映射实例,里面包含源程序,测试程序,映射文档


Web 开发
