0

I want to fetch different columns from different tables in hibernate. My query is :

@NamedQuery(name="findAllfundSalesCreditCalc",query=" select distinct SF.subFundName, SF.id, case when FCM.subFundId is null "
                +" then 'Not yet added' else 'Already exists' end as ExistsOrNot,CCM.calculationMethodName," 
                +" FCM.effectiveFromDate, FCM.effectiveToDate,FCM.paymentFrequencyId,"
                +" FCM.firstPaymentDate from FundSalesCreditCalcMethod FCM ,SubFund SF , Class C ,"
                +" SC_Class SCC, SalesCreditCalcMethod CCM where SF.id = FCM.subFundId and "
                +" CCM.id = FCM.salesCreditCalcMethodId and "
                +" C.id = SF.id and "
                +" SCC.classId = C.id")

I am retrieving the data in a list.

List<FundSalesCreditCalcMethod> fundSalesCreditCalc = getFundSalesCreditCalcMethodDao().getFundSalesCreditCalc(); 

public List<FundSalesCreditCalcMethod> getFundSalesCreditCalc() {
        return this.entityManager.createNamedQuery("findAllfundSalesCreditCalc").getResultList();
    }

public List<FundSalesCreditCalcMethodDTO> getFundSalesCreditCalculation() {
/*      List<Object> fundSalesCreditCalc = getFundSalesCreditCalcMethodDao().getFundSalesCreditCalc();*/
        List<FundSalesCreditCalcMethod> fundSalesCreditCalc = getFundSalesCreditCalcMethodDao().getFundSalesCreditCalc();
        List<FundSalesCreditCalcMethodDTO> fundSalesCreditCalcMethodDtos = new ArrayList<FundSalesCreditCalcMethodDTO>();
        for(FundSalesCreditCalcMethod fundSalesCredit: fundSalesCreditCalc) {
            fundSalesCreditCalcMethodDtos.add(DTOCreator.createfundSalesCreditCalcDTO(fundSalesCredit));
        }
        return fundSalesCreditCalcMethodDtos;
    }

this is giving error :java.lang.classcastexception.

9
  • pls provide the code from getFundSalesCreditCalc method Commented Mar 21, 2016 at 13:00
  • You should really show us the full Java code where you are making the JPA call. Commented Mar 21, 2016 at 13:02
  • If you execute a query with Hibernate that return multiple values usually you get List<Object[]>. Maybe the ClassCastException is being thrown when you try to access the returned list. Commented Mar 21, 2016 at 13:05
  • I have added the whole code.Can you please suggest where I am doing wrong. Commented Mar 21, 2016 at 13:12
  • 1
    @shree In this link you may find what your looking for and additional links for extended info stackoverflow.com/questions/10829197/… Commented Mar 21, 2016 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.