点石互动

导航

 
在写hql时,应注意 语句中要严格对照 实体类的 各个属性 包括大小写等

例如

实体如下:

Java代码 复制代码 收藏代码
  1. @Entity
  2. @Table(name="apcm_flow")
  3. public class Flow extends Page implements Serializable {
  4. private Integer ID;
  5. //**流量流向表头信息
  6. private User user;//用户
  7. private County county;//地区
  8. private Date rptdate;//报表时间
  9. private Date createTime;//上报时间
  10. //**表体
  11. private List<FlowBuy> flowBuys;//购入表体
  12. private List<FlowSale> flowSales;//销售表体


在写Impl中如果用到hql 则注意:
Java代码 复制代码 收藏代码
  1. String rptDateSql = " and f.rptdate=to_date('"+rptDate+"', 'yyyy-mm-dd')";
  2. StringBuffer hql = new StringBuffer("from Flow f where 1=1");
  3. hql.append(countySql).append(" order by f.createTime desc");


上面代码中 rptdate第二单词首字母为小写 而 createTime第二单词首字母为大写 如果大小写没有按照实体的规定来写 会导致错误
Java代码 复制代码 收藏代码
  1. could not resolve property: rptDate of:....


经验是 以后要统一规范 避免前面写好了 后面忘记了 
posted on 2013-02-18 20:23  点石互动  阅读(125)  评论(0编辑  收藏  举报