0

I have followed this answer to avoid 'path exception' error in the hibernate query, but now I'm facing an exception given in the description below.

Here is my query:

select lo from Transaction tr join tr.Loan lo on lo.loanId = tr.Loan.loanId 
  where 
    lo.loan_status = 'open' and 
    category = 'principal' and 
    date >= :fromDate and 
    date <= :toDate 
  order by date asc

Error:

org.hibernate.QueryException: could not resolve property: Loan of: model.core.Transaction[select lo from model.core.Transaction tr join tr.Loan lo on lo.loanId = tr.Loan.loanId where lo.loan_status = 'open' and category = 'principal' and date >= :fromDate and date <= :toDate order by date asc]
        at org.hibernate.QueryException.generateQueryException(QueryException.java:120)
        at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)
        at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150)
        at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:155)
        at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:764)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:495)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
        at utility.DbSessionManager.buildSessionFactory(DbSessionManager.java:16)
        at utility.DbSessionManager.<clinit>(DbSessionManager.java:7)
        at utility.LoanManager.getLoans(LoanManager.java:65)
        at controller.LoanController.getLoan(LoanController.java:45)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
halfer
  • 19,824
  • 17
  • 99
  • 186
liwevire
  • 782
  • 2
  • 9
  • 21
  • 1
    It says: *could not resolve property: Loan of: model.core.Transaction* Does your Transaction class has a property named "Loan"? I doubt it, since properties in Java normally start with a lowercase letter. Also, remove the on clause. http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#hql-explicit-join – JB Nizet Jul 23 '17 at 11:29
  • Problem is with the upper case first letter. Now I'm getting `org.hibernate.hql.internal.ast.QuerySyntaxException: transaction is not mapped [select lo from transaction tr join tr.loan lo on lo.loanId = tr.loan.loanId where lo.loanStatus = 'open' and tr.category = 'principal' and tr.date >= :fromDate and tr.date <= :toDate order by date asc]` – liwevire Jul 23 '17 at 11:42
  • Also I have tried the other way, `org.hibernate.hql.internal.ast.QuerySyntaxException: loan is not mapped [select lo from loan lo join lo.transaction tr on lo.loanId = tr.loan.loanId where lo.loanStatus = 'open' and tr.category = 'principal' and tr.date >= :fromDate and tr.date <= :toDate order by date asc]` FYI. Relationship: Loan to Transaction -> One to Many – liwevire Jul 23 '17 at 11:47
  • 1
    Your class is named Transaction, not tranaction. – JB Nizet Jul 23 '17 at 11:48
  • Cheers! Yes it is. FYI, I removed 'on' condition also to get it working. `select lo from Transaction tr join tr.loan lo where lo.loanStatus = 'open' and tr.category = 'principal' and tr.date >= :fromDate and tr.date <= :toDate order by date asc` – liwevire Jul 23 '17 at 12:03
  • [Why on condition is to be removed](https://stackoverflow.com/a/9069314/7268798) – liwevire Jul 23 '17 at 12:15

0 Answers0