主表:SellBill的pojo字段:    private String fldId;
    private Date fldSellDate;
    ...
详表:Details.java的pojo字段:    private SellDetailsId id;
    private String fldProductId;
    private Double fldNum;
    private Double fldPrice;
    ...details.hbm.xml文件:
<composite-id name="id" class="com.pojo.SellDetailsId">
    <key-property name="fldLine" type="java.lang.Integer">
         <column name="fld_line" />
    </key-property>
    <key-many-to-one name="sellBill" class="com.pojo.SellBill">
         <column name="fld_bill_id" length="50" />
    </key-many-to-one>
    省略其他配置
</composite-id>
自己封装了一个pageQuery的HQL方法     //需求:for循环前年、本年、明年的单据
    Date startDate;//开始日期,为前年的第一天日期
    Date endDate;//结束日期
    Calendar c = Calendar.getInstance();
    c.setTime(start);
    for(int ins=0; ins<3; ins++) {
        startDate = c.getTime();
        c.add(Calendar.YEAR, 1);
        endDate = c.getTime();
        this.billDAO.pageQuery("select sum(fldPrice*fldNum) from Details where id.sellBill.fldSellDate>=? and id.SellBill.fldSellDate<?", null, null, startDate, endDate).get(0).toString())
 }为什么循环第一次就报空指针异常呢(pageQuery)?

解决方案 »

  1.   

    不会billDAO的get、set方法没有吧?
      

  2.   

    DAO是spring注入的,都有set和get方法。这是pageQuery的代码:
       public List pageQuery(final String hql, final Integer page, final Integer size, final Object... agrs) {
            return super.getHibernateTemplate().executeFind(new HibernateCallback() {
               
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    Query q = session.createQuery(hql);
                    if (agrs != null) {
                        for (int i = 0; i < agrs.length; i++) {
                            q.setParameter(i, agrs[i]);
                        }
                    }
                    if (page != null && size != null) {
                        q.setFirstResult((page - 1) * size).setMaxResults(size);
                    }
                    return q.list();
                }
            });
            
        }