hibernate 三个表关联查询问题,求解

egewg3 2012-05-24 11:44:21
DistrictVO

private String districtNum; // 管理区域编号
private String districtName; // 管理区域名称


AreaManagerVO

private int managerId;// 用户编号
private String managerArea; //管理区域编号(集合可以有多个编号 用逗号分开 如 370000,100000,370829)


UserVO
private int userid;用户编号
private String username;用户名字

区域编号 数据库内容有 一条是 370000,371599,234444 也就是AreaManagerVO表 对 DistrictVO表是存在 一对 多

查询实现

查出 用户编号 用户名称 管理区域 。

列子 1 李玉 长清,平阴,章丘
...全文
91 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
egewg3 2012-05-24
  • 打赏
  • 举报
回复
表不可以变的,每个表都有它的用途,DistrictVO表 是外链数据库

<bean id="iDistrict" parent="baseTransaction">
<property name="target">
<bean class="com.jtwlw.storage.impl.boss.district.DistrictImpl">
<property name="sessionFactory">
<ref bean="busidbFactory" />
</property>
<property name="busidbjdbc">
<ref bean="busidbjdbc" />
</property>
</bean>
</property>
</bean>
_jerrytiger 2012-05-24
  • 打赏
  • 举报
回复
表本身就设计的不规范

DistrictVO
private String districtNum; // 管理区域编号
private String districtName; // 管理区域名称
private UserVO userVo ; //管理该区域的用户


UserVO
private int userid;用户编号
private String username;用户名字
private Set<DistrictVO> destrictVos ; //管理区域

这样设计才合理一些 ,
查询的时候 直接查询 "from UserVO where userid = 1" 得到UserVo ,然后就能得到destrictVos 了。

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧