簡體   English   中英

Hibernate查詢未返回結果

[英]Hibernate Query not returning results

長話短說,我的休眠查詢僅在從調用循環首次訪問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;

}

問題在排隊

dataList = pricing_dataDao.findPricing(currentlyPricing.getRateClass().trim(), 
                        currentUser.getUtility(), currentUser.getStart_month(), 
                        Integer.valueOf(currentUser.getStart_year()), d1, "12", totalVolume, totalVolume);  

Rate Class字段來自一個csv下拉列表,該列表根據選擇了多少個字段而被扔到一個列表中,並且沿着這行,我顯然不正確地將它們分開,因此我必須添加.trim() 因此,對於將來遇到任何麻煩的人來說, Hibernate查詢確實可以正常運行,並且如果您對查詢的String輸入不能正常運行,請嘗試.trim()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM