.................................
String hql="select task,insL.InsName,insR.InsName,tra"
+" from Institution as insL,Transition as tra,Institution as insR,Task as task"
+" where task.id=tra.taskId"
+" and insL.InsId=tra.foreNode"
+" and insR.InsId=tra.aftNode"
+(condition==null?(""):condition);
List list=null;
try{
Query query=session.createQuery(hql);
list=query.list();tx.commit();
}
catch(Exception e){
tx.rollback();
e.printStackTrace();
list=null;
}
finally{
session.close();
}
if(list!=null){
for(int i=0;i<list.size();i++){
TransitionDTO transitionDTO=new TransitionDTO();
Object[] obs=(Object[])list.get(i);
Task tmp_task=(Task)obs[0];
transitionDTO.taskId=tmp_task.getId();
transitionDTO.foreInsName=(String)obs[1];
transitionDTO.aftInsName=(String)obs[2];
Transition tmp_trs=(Transition)obs[3];
transitionDTO.transitionId=tmp_trs.getId();
.....................
注意HQL语句中from后面为类名,"."号后面为属性名,必须和hbm.xml中的相一致,而不是和类名中的属性名相同(尽管很多时候他们是相同的,但HQL语句中的必须和hbm中相一致)
the above code works,while the hbm.xml files don't contain the <many-to-one>properties