2010.01.13——hql 的时间问题 弄了一下午 郁闷

2010.01.13——hql 的时间问题 弄了一下午 郁闷
Dao的方法如下
public Double getYuliang(String stcd, Date startTime, Date endTime) {   
CustomerContextHolder.setCustomerType("query_su9921");
String hql = "select sum(s.DYP) from ST_PPTN_R s where s.STCD=? " +
"and s.TM>to_date(?,'yyyy-MM-dd HH24:mi:ss') " +
"and s.TM<to_date(?,'yyyy-MM-dd HH24:mi:ss')";
System.out.println(startTime);
System.out.println(endTime);
String s = FormatDate.formatDate(startTime, "yyyy-MM-dd HH:mm:ss");
String e = FormatDate.formatDate(endTime, "yyyy-MM-dd HH:mm:ss");
System.out.println(s);
System.out.println(e);
Object[] values = {stcd,s,e};

log.info(hql);
return (Double)this.template.find(hql,values).get(0);
}

测试的方法:
@Test  
public void testGetYuliang() throws ParseException {
String stcd = "62518600";
YuliangDao yuliangDao = (YuliangDao) ctx.getBean("yuliangDao");
Date startTime = new Date();
System.out.println(startTime);
Calendar endTime = Calendar.getInstance();
endTime.setTime(startTime);
endTime.add(Calendar.YEAR, 1);
System.out.println(endTime.getTime());

Double num = yuliangDao.getYuliang(stcd, startTime, endTime.getTime());
System.out.println(num);
Assert.assertNotNull(num);
}

junit的主要错误信息如下:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: TM of: com.pojo.rthi.ST_PPTN_R [select sum(s.DYP) from com.pojo.rthi.ST_PPTN_R s where s.STCD=? and s.TM>to_date(?,'yyyy-MM-dd HH24:mi:ss') and s.TM<to_date(?,'yyyy-MM-dd HH24:mi:ss')]; nested exception is org.hibernate.QueryException: could not resolve property: TM of: com.pojo.rthi.ST_PPTN_R [select sum(s.DYP) from com.pojo.rthi.ST_PPTN_R s where s.STCD=? and s.TM>to_date(?,'yyyy-MM-dd HH24:mi:ss') and s.TM<to_date(?,'yyyy-MM-dd HH24:mi:ss')]

竟然说找不到TM 郁闷 我的映射肯定是没错,这个问题弄了一个下午,到最后原因竟然是:
把s.TM 改为TM就对了 原因不明 终于解决了 我是内牛满面啊

ps:另外那个dao的方法可以简单化为:
public Double getYuliang(String stcd, Date startTime, Date endTime) {
CustomerContextHolder.setCustomerType("query_su9921");
String hql = "select sum(s.DYP) from ST_PPTN_R s where s.STCD= ? and TM between ? and ?";
log.info(startTime);
log.info(endTime);
Object[] values = {stcd,startTime,endTime};
log.info(hql);
return (Double)getHibernateTemplate().find(hql,values).get(0);
}
就是说可以直接用Date对象来注入
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值