如何使用 Hibernate操作SQL数据库中视图所返回的结果 的集合
xx.hbm.xml文件内容:
<hibernate-mapping>
<class name="DBDAO.ViewUserQuestion" table="view_User_Question" schema="dbo" catalog="BBSDB">
<composite-id name="id" class="DBDAO.ViewUserQuestionId">
<key-property name="qid" type="java.lang.Integer">
<column name="qId" />
</key-property>
<key-property name="qtId" type="java.lang.Integer">
<column name="qtId" />
</key-property>
<key-property name="qtitle" type="java.lang.String">
<column name="qTitle" length="100" />
</key-property>
<key-property name="qintegral" type="java.lang.Integer">
<column name="qIntegral" />
</key-property>
<key-property name="pubName" type="java.lang.String">
<column name="pubName" length="20" />
</key-property>
<key-property name="pubUid" type="java.lang.Integer">
<column name="pubUId" />
</key-property>
<key-property name="pubTime" type="java.util.Date">
<column name="pubTime" length="23" />
</key-property>
<key-property name="revertName" type="java.lang.String">
<column name="revertName" length="20" />
</key-property>
<key-property name="revertUid" type="java.lang.Integer">
<column name="revertUId" />
</key-property>
<key-property name="rvtTime" type="java.util.Date">
<column name="rvtTime" length="23" />
</key-property>
<key-property name="qstate" type="java.lang.Integer">
<column name="qState" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
xxDAO类中:
public List getVeiwUserQuestionByTid(int tid){
String sql="from ViewUserQuestion v where v.id.qtId=2";//+tid;
List list=viewDB.getView(sql);
System.out.println("查询类DAO中list大小:"+list.size());
for(int i=0;i<list.size();i++){
ViewUserQuestion vq=(ViewUserQuestion)list.get(i);
System.out.println("查询类DAO中list类型:"+vq);
}
//viewDB.destory();
return list;
}
打印的结果:
Session开始
查询类DAO中list大小:2
查询类DAO中list类型:DBDAO.ViewUserQuestion@14937e2
查询类DAO中list类型:null
查询的结果也应该是两条记录。。
可是为什么获取第二条时为空。。。