102. .getCountAthlete().equals(castOther.getCountAthlete())))
103. && ((this.getCountTeam() == castOther.getCountTeam()) || (this
104. .getCountTeam() != null
105. && castOther.getCountTeam() != null && this
106. .getCountTeam().equals(castOther.getCountTeam())))
107. && (this.getEveId() == castOther.getEveId())
108. && ((this.getRace() == castOther.getRace()) || (this.getRace() != null
109. && castOther.getRace() != null && this.getRace()
110. .equals(castOther.getRace())))
111. && (this.getUserId() == castOther.getUserId())
112. && (this.getId() == castOther.getId());
113. }
114.
115. public int hashCode() {
116. int result = 17;
117.
118. result = 37
119. * result
120. + (getCountAthlete() == null 0 : this.getCountAthlete()
121. .hashCode());
122. result = 37 * result
123. + (getCountTeam() == null 0 : this.getCountTeam().hashCode());
124. result = 37 * result + (int) this.getEveId();
125. result = 37 * result
126. + (getRace() == null 0 : this.getRace().hashCode());
127. result = 37 * result + (int) this.getUserId();
128. result = 37 * result + (int) this.getId();
129. return result;
130. }
131.
132. }
我们知道,视图是没有主键的,视图就是一张虚拟表。hibernate对没有主键的表逆向生成的时候,是会生成
CountView.java
CountViewId.java
两个类的,XxxId.java这个类里面的属性才是我们需要的数据.
③映射文件如下:
CountView.hbm.xml
1. < xml version="1.0" encoding="utf-8" >
2. 3. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4.
7.
8.
9.
10.
11.
12.
13.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
④CountViewDaoImpl .java如下:
1. package com.yaxing.daoImpl;
2.
3. import java.util.List;
4.
5. import org.hibernate.Query;
6. import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
7.
8. import com.yaxing.dao.CountViewDao;
9. import com.yaxing.entity.CountView;
10. import com.yaxing.util.PageModel;
11.
12. public class CountViewDaoImpl extends HibernateDaoSupport implements CountViewDao {
13.
14. @Override
15. public List
16. // TODO Auto-generated method stub
17. return this.getHibernateTemplate().find("select id.countAthlete,id.countTeam,id.race,id.eveId from CountView");
18. }
19.
20. }
可以看到第17行:
1. return this.getHibernateTemplate().find("select id.countAthlete,id.countTeam,id.race,id.eveId from CountView");
字段是id.countAthlete这种,因为CountView.java的11行
1. private CountViewId id;
我们这只有一个返回所有的List集合
⑤Action中如下:
1. public String listCountView() throws Exception {
2. try {
3. List allValue = this.countViewService.listCountV