长话短说明我的hibernate查询仅在从调用循环首次访问DAO时返回结果。
到目前为止,我已尝试手动设置值,并且每次返回其预期结果集,但每当它变为动态查询时,它返回并返回结果集。然而,这不是应该给我的东西。我已经尝试了多个查询它的实例,它通过循环使用2个实例的完全相同的输入,它只会在第一次给我结果。
编辑: 我已经缩小到我的问题是涉及rate_class&效用变量都是String&。如果这两个是硬编码的'即;将查询更改为只放入" x"和" y"我得到了我想要的东西。我已使用修改后的版本更新了代码。
呼叫循环:
public void RetrievePricing(){
for(int x=0; x<pricing.size(); x++){
//grab the pricing object to be priced
currentlyPricing = pricing.get(x);
//look back 7 days at max for pricing
for(int y=0; y<7; y++){
//query for pricing matches
rate_class = currentlyPricing.getRateClass();
utility = currentUser.getUtility();
dataList = pricing_dataDao.findPricing(rate_class,
utility, currentUser.getStart_month(),
Integer.valueOf(currentUser.getStart_year()), d1, "12", totalVolume, totalVolume);
//if we didn't find one decrement a day
if(dataList.size() == 0 && x<=0){
Calendar cal = new GregorianCalendar();
cal.setTime(d1);
cal.add(Calendar.DATE, -1);
d2 = cal.getTime();
d1 = new java.sql.Date(d2.getTime());
}
//if we did find something attempt to add it and break out of the inner loop
else{
if(currentlyPricing.getName().isEmpty() == false && dataList.isEmpty() == false){
pricingMap.put(currentlyPricing.getName(), dataList);
break;
}
}
}
}
}
DAO功能
public List<Pricing_Data> findPricing(String rate_class, String utility, String start_month, int start_year, Date expiration_date, String term, double low_kwh, double high_kwh) {
List<Pricing_Data> tempList = new ArrayList<Pricing_Data>();
tempList = getHibernateTemplate().find("from Pricing_Data where rate_class=? and utility=? "
+"and start_month=? and start_year=? and expiration_date=? and term=? and high_kwh>=? and low_kwh<=?"
, rate_class, utility, start_month, start_year, expiration_date.toString(), term, low_kwh, high_kwh);
return tempList;
}
答案 0 :(得分:0)
问题出在
行dataList = pricing_dataDao.findPricing(currentlyPricing.getRateClass().trim(),
currentUser.getUtility(), currentUser.getStart_month(),
Integer.valueOf(currentUser.getStart_year()), d1, "12", totalVolume, totalVolume);
Rate Class
字段来自csv下拉列表,该列表被放入列表中,具体取决于选择的字段数量以及沿线的某处我显然将它们错误地分开,因此我不得不添加{ {1}}。因此,对于未来遇到此问题的任何人,.trim()
查询都能正常运行,如果您的Hibernate
查询输入功能无法正常运行,请尝试String
!