急!在线等 hibernate如何存储多表关联

ttwhkl ttwhkl 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在有一个大的页面,里面有一些有很多提交按钮

我现在每点一次提交按钮,通过anction 提交一次,把数据存到httpsession里面

最后我点保存按钮

才把刚才所有提交的数据

保存主表时与它关联的(多的一方)数据库全部保存

我是这么写的
if (session.getAttribute("strategy") == null) {
strategy = new Strategy();

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




如下配置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" />

现在实现不了
问这么能合理的实现存主表,子表也存储的功能

...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
ttwhkl
Java EE 67,535 成员 225,843 内容