简体   繁体   English

Hibernate查询未返回结果

[英]Hibernate Query not returning results

Long story short my hibernate query is only returning results on its first visit to the DAO from the calling loop. 长话短说,我的休眠查询仅在从调用循环首次访问DAO时返回结果。

So far I've tried manually setting the values and that returns its expected result set every time however whenever it turns into a dynamic query it is returning and empty resultset. 到目前为止,我已经尝试过手动设置值,并且每次都返回其预期结果集,但是每当它变为动态查询时,它就会返回并且结果集为空。 However that's not what it should be giving me. 但是那不是应该给我的。 I've tried multiple instances of querying it with the exact same input for 2 instances through the loop and it will only ever give me results on the first time through. 我已经尝试通过循环为2个实例使用完全相同的输入来查询它的多个实例,它只会在第一次使用时给我结果。

EDIT: I've narrowed down to my issue is involving the rate_class & utility variables both of which are String's. 编辑:我已经缩小到我的问题涉及rate_class和实用程序变量,这两个都是String的。 If these two are 'hardcoded' ie; 如果这两个是“硬编码的”,即; changing the query to just put in "x" and "y" I get what I want. 将查询更改为仅放入“ x”和“ y”,即可得到所需的内容。 I've updated the code with my modified version. 我已经用修改后的版本更新了代码。

Calling Loop: 调用循环:

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 Function 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;

} }

Issue was in the line 问题在排队

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

the Rate Class field is coming from a csv drop down list that is being thrown into a list depending on how many fields were being selected and somewhere along the line I apparently separated them incorrectly so I had to add a .trim() . Rate Class字段来自一个csv下拉列表,该列表根据选择了多少个字段而被扔到一个列表中,并且沿着这行,我显然不正确地将它们分开,因此我必须添加.trim() So for anyone stumbling upon this in the future the Hibernate queries do function correctly and if your String input to your queries is not correctly functioning try a .trim() ! 因此,对于将来遇到任何麻烦的人来说, Hibernate查询确实可以正常运行,并且如果您对查询的String输入不能正常运行,请尝试.trim()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM