分页的关联查询
public List queryTrade(final int offset,final int length,final Date startdate,final Date enddate,final String comUsername){
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
StringBuffer hql=new StringBuffer();
try{
String queryString = "select A.comUsername,A.joinId,B.dtBuyTime,B.decAmount from BarOrderInfo A, EcpRichJoin B where A.comUsername=? and A.joinId=B.intOrdeId and B.dtBuyTime >=? and B.dtBuyTime <=? ";
Query query = session.createQuery(queryString);
query.setString(0, comUsername);
query.setDate(1,startdate );
query.setDate(2,enddate);
query.setFirstResult(offset);
query.setMaxResults(length);
List result=new ArrayList();
List list=query.list();
TradeReportVO trvo=null;
for(int i=0;i<list.size();i++){
trvo=new TradeReportVO();
Object o[]=(Object[])list.get(i);
System.out.println("o.length--->"+o.length);
trvo.setComUsername(o[0].toString());
trvo.setJoinId(o[1].toString());
trvo.setDtBuyTime(o[2].toString());
trvo.setDecAmount(o[3].toString());
System.out.println(o[0].toString()+"-"+o[1].toString()+"-"+o[2].toString()+"-"+o[3].toString());
result.add(trvo);
}
return result;
}catch(RuntimeException re){
log.error(re.getMessage());
log.error("find failed", re);
log.error("hql====" + hql);
throw re;
}
}
});
}
直接查询
/**
* 查找交班记录
* @return
*/
public List findWorkShift(String VcComUsername,String vcCoaUsername,Date startDatetime,Date endDatetime){
try {
String queryString = "from BarCommerOpaction as model where "
+ " model.VcComUsername=? "
+ " and model.vcCoaUsername =? "
+ " and model.dtCoaTime > ? "
+ " and model.dtCoaTime <= ? ";
return getHibernateTemplate().find(queryString,new Object[]{VcComUsername,vcCoaUsername,startDatetime,endDatetime});
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
当Hibernate 使用时间类型时,要记住Date类型与Timestamp类型的区别,Date只取到日期,不取时间的。
posted on 2008-07-01 16:41
有猫相伴的日子 阅读(494)
评论(0) 编辑 收藏 所属分类:
ibatis/hibernate/持久层技术