hibernate 数据库的关联查询问题
直接题目(我做的是一个论坛):
如图:
我想查询回复数(reply)排名前3的话题(topic)
该怎么搞?
回答可以是hibernate的query查询也可以是mysql查询语句,O(∩_∩)O谢谢。 数据库 Hibernate MySQL
[解决办法]
public List<Topic> queryFirstThreeTopic(){
Session session = null;
Query query = null;
List<RoomReserve> list = null;
try {
String hql = "select * from Topic where id IN(select top 3 topicId from Reply r order by r.floor DESC )";
query = session.createQuery(hql);
list = query.list();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
if (session.isOpen()) {
session.close();
}
}
}
return list;
}