Hibernate操纵视图详解 (三)

2014-11-24 07:51:05 · 作者: · 浏览: 4
iew();
4. listCountView = new ArrayList();
5. Iterator it = allValue.iterator();
6. while (it.hasNext()) {
7. Object[] all = (Object[]) it.next();
8. CountViewId countViewId = new CountViewId();
9. countViewId.setCountAthlete((Integer) all[0]);
10. countViewId.setCountTeam((Integer) all[1]);
11. countViewId.setRace((String) all[2]);
12. countViewId.setEveId( (Long)all[3]);
13.
14. listCountView.add(countViewId);
15. }
16.
17. } catch (Exception e) {
18. e.printStackTrace();
19. return INPUT;
20. }
21. return SUCCESS;
22.
23. }
第3行,如果直接写成

1. listCountView = this.countViewService.listCountView();
这个页面查询的是没有结果的!
是因为:Hibernate 映射视图会生成联合主键.在查询时,如果联合主键里有一项值为null,则整个结果返回null。然而,我们的查询中不可避免的存在值为null的情况,这种情况下该怎么办呢?
解决办法:需要做4-11行代码的转换才行!
给 listCountView 迭代的添加内容!

摘自 幽灵柯南的技术blog