主表: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)?
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)?
解决方案 »
- ioc 注入空值
- 根据id查询其他数据
- 请大牛帮忙,jsp+tomcat+sql2000报错信息
- java:一个值得挑战的问题,很长时间无人解决,有兴趣者进
- 高分求iPlanet Application Server的下载地址!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 如何用servlet文件,读取文件内容?请给一点提示代码。谢谢!
- 求围观,iframe存在的问题
- spring mvc如果插件化问题
- 一个不成熟的问题关于session请赐教
- 因公司网站需要,请帮我介绍几个支持jsp加数据库的web空间。先谢了!!
- 麻雀虽小,五脏俱全:用DOJO写一个最简单的控件
- queryForRowSet结果和mysql客户端结果不一致问题?
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();
}
});
}