67,513
社区成员
发帖
与我相关
我的任务
分享
PreparedStatement st = null;
Session session = getSession();
ResultSet rs = null;
String sql = "select id,user_id,content,isaviable,createtime,business_info_id,overallimpression,discuss_sub_count,collection_count,read_status,forward_count from business_discusses a,( select max(id) as ids from business_discusses where isaviable = true group by business_info_id) b where a.id = b.ids order by createtime desc LIMIT 0,10";
List<BusinessDiscusses> list = new ArrayList<BusinessDiscusses>();
try {
// Transaction t = session.beginTransaction();
st = session.connection().prepareStatement(sql);
rs = st.executeQuery();
// t.commit();
UsersDAO userDao = new UsersDAO();
BusinessInfoesDAO infoDao = new BusinessInfoesDAO();
while (rs.next()) {
BusinessDiscusses dis = new BusinessDiscusses();
dis.setId(rs.getInt("id"));
dis.setUsers(userDao.findById(rs.getInt("user_id")));
dis.setBusinessInfoes(infoDao.findById(rs.getInt("business_info_id")));
dis.setContent(rs.getString("content"));
dis.setIsaviable(rs.getBoolean("isaviable"));
dis.setCreatetime(rs.getTimestamp("createtime"));
dis.setOverallimpression(rs.getInt("overallimpression"));
dis.setDiscussSubCount(rs.getInt("discuss_sub_count"));
dis.setCollectionCount(rs.getInt("collection_count"));
dis.setReadStatus(rs.getBoolean("read_status"));
dis.setForwardCount(rs.getInt("forward_count"));
list.add(dis);
}
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public Users findById(java.lang.Integer id) {
log.debug("getting Users instance with id: " + id);
try {
Users instance = (Users) getSession().get(
"com.housecommunity.db.model.Users", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}