hibernate中用原生sql查询3个表连接,其中2个是相同的表,怎么在hibernate中写。
selectc.cname,c.croom,t1.tname,t2.tnamefromsouthit_classescleftjoin(select*fromsouthi...
select c.cname,c.croom,t1.tname,t2.tname from southit_classes c left join (select * from southit_teacher where type=1) t1 on c.cno=t1.tclasses left join (select * from southit_teacher where type=2) t2 on c.cno=t2.tclasses;
我写的是:
getSession().createSQLQuery(sql).add.addEntity("c", Classes.class).addEntity("t1", Teacher.class).addEntity("t2", Teacher.class).list();这样不行 展开
我写的是:
getSession().createSQLQuery(sql).add.addEntity("c", Classes.class).addEntity("t1", Teacher.class).addEntity("t2", Teacher.class).list();这样不行 展开
展开全部
getSession().createSQLQuery(sql).addEntity(Classes.class);
追问
2个基于Teacher的表都不管了?
追答
select c.cname,c.croom,t1.tname as t1name,t2.tname as t2name from southit_classes c left join (select * from southit_teacher where type=1) t1 on c.cno=t1.tclasses left join (select * from southit_teacher where type=2) t2 on c.cno=t2.tclasses;
getSession().createSQLQuery(sql)
.addScalar("cname",StandardBasicTypes.STRING)
.addScalar("croom",StandardBasicTypes.STRING)
.addScalar("t1name",StandardBasicTypes.STRING)
.addScalar("t2name",StandardBasicTypes.STRING)
.list();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询