public List<Object[]> findElecCommonMsgListByCurrentDate(String currentDate) {
final String sql = "SELECT o.StationRun as stationRun,o.DevRun as devRun " +
"FROM Elec_CommonMsg o " +
"WHERE o.CreateDate = '" + currentDate + "'";
List<Object[]> list = (List<Object[]>)this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createSQLQuery(sql);
//也可以createSQLQuery(sql).addScalar("stationRun",Hibernate.STRING)
//.addScalar("devRun",Hibernate.STRING);
//其中"addScalar"确定返回类型,值的注意的是,不管sql语句中选择返回多少的数据,一旦使用了addScalar方法,其它没有申明返回类型的数据都不会被返回
return query.list();
}
});
return list;
}
hibernate通过HibernateCallback()调用底层session
最新推荐文章于 2017-10-13 00:55:10 发布