0

I would like to create a JPA query that selects all entities matching some conditions, but I receive an error.

My select is:

 select count(*) from Employee emplWithLicence  JOIN FETCH emplWithLicence.firma fa JOIN FETCH emplWithLicence.user userWithLicence JOIN FETCH userWithLicence.contact ctc LEFT OUTER JOIN FETCH userWithLicence.licence lice where userWithLicence.active = true and emplWithLicence.firma.name like 'Be%' 

In the future more conditions may come to the where clause, but this should not change my logic. Now, when I try to execute the logic above I receive the error below:

Caused by: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=fa,role=at.home.digest.model.dave.Employee.firma,tableName=firma,tableAlias=firma1_,origin=empl employee0_,columns={employee0_.firma_id ,className=at.home.digest.model.dave.Firma}}]
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:217)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:1018)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:786)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:677)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:271)
at org.hibernate@5.3.10.Final//org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191)
... 162 more

what is my problem, how can I fix it?

Alex Mi
  • 1,409
  • 2
  • 21
  • 35
  • 1
    check [this](https://stackoverflow.com/a/12459909/12083015) – Erwin Apr 10 '23 at 07:08
  • 1
    https://stackoverflow.com/questions/12459779/query-specified-join-fetching-but-the-owner-of-the-fetched-association-was-not – Ksu Apr 10 '23 at 09:17

0 Answers0