急!在线等 hibernate如何存储多表关联
现在有一个大的页面,里面有一些有很多提交按钮
我现在每点一次提交按钮,通过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" />
现在实现不了
问这么能合理的实现存主表,子表也存储的功能
我现在每点一次提交按钮,通过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" />
现在实现不了
问这么能合理的实现存主表,子表也存储的功能
...全文
相关推荐
hibernate多表联合查询
hibernate多表联合查询实例,很经典的查询语句和总结.
Hibernate双向关联:一对多与多对一配置详解
一对多和多对一关系是关系型数据库中最常见的关系类型之一,它们在对象关系映射(ORM)框架如Hibernate中尤为重要。在一对多关系中,一个父实体可以关联多个子实体,但每个子实体只能关联到一个父实体。多对一关系是其对称,即多个子实体可以关联到同一个父实体,但父实体可以关联到任何数量的子实体。在Hibernate中,这些关系可以通过注解或XML配置实现,它们将关系映射到数据库中的表。例如,在一对多关系中,我们可能在父表中有一个外键指向子表,而多对一关系则相反,子表中会有一个外键指向父表。
hibernate 多表关联 中间表
hibernate 中间表 希望给予新手帮助
hibernate 进行多表查询每个表中各取几个字段
NULL 博文链接:https://08284008.iteye.com/blog/1456476
Hibernate基于连接表的一对多单向关联
NULL 博文链接:https://paladin1988.iteye.com/blog/1627678


