1.left outer join
final String sql = "SELECT A.* FROM xxx A LEFT JOIN xxx B
ON A.xxx = B.xxx WHERE B.xxx = ?";
Listresult = getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Listlist = (List )session.createSQLQuery(sql)
.addEntity("A", MyFriendDynamic.class)
.setString(0, userId)
.list();
return list;
}
});
return result;
2. select count(*) from xxx
final String sql = "SELECT count(*) as count FROM xxx A LEFT JOIN xxx B
ON A.xxx = B.xxx WHERE B.xxx = ?";
Integer count = (Integer) getHibernateTemplate().execute(
new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Integer query = (Integer)session.createSQLQuery(sql)
.addScalar("count", Hibernate.INTEGER)
.setString(0, userId)
.uniqueResult();
return query;
}
});
return count;
0 意見:
張貼留言