The application works previously.
When we upgrade spring boot from 2.3.4.RELEASE to 2.5.14, the application run into this exception: QuerySyntaxException: *** is not mapped.
I can't tell whether all entities would but I've seen multiple entities failing with this exception. Here's an example:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: ModelSummary is not mapped [from ModelSummary where :currentTime - lastUpda
teTime <= :timeFrame]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:138) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:734) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:114) ~[hibernate-core-5.4.33.jar:5.4.33]
at jdk.internal.reflect.GeneratedMethodAccessor138.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
.......................................
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: ModelSummary is not mapped [from ModelSummary where :currentTime - lastUpdateTime <= :timeFrame]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:613) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:725) ~[hibernate-core-5.4.33.jar:5.4.33]
... 160 more
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: ModelSummary is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:169) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:77) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:333) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3765) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3654) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:737) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:593) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:330) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:278) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:276) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:613) ~[hibernate-core-5.4.33.jar:5.4.33]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:725) ~[hibernate-core-5.4.33.jar:5.4.33]
... 160 more
btw, I don't find the source code of org.hibernate.hql.internal.ast.util.SessionFactoryHelper in https://github.com/hibernate/, I believe it'll help if someone could point me to it.
I want to put this as an answer as this could free someone let him/her go ahead if he/she runs into the same situation.
We're using org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean to scan entities, tens of beans of this type are defined.
It happened that one of these beans set
primary="true", which is responsible for scanning two packages.The result is only entities in these two packages get registered into
sfi.getMetamodel().entityPersisters()inSessionFactoryHelper, as I mentioned in one of my comments.All other entities are ignored,
QuerySyntaxException: *** is not mappedthrows when you access these ignored entities.The issue gets fixed once removing
primary="true".But I think this is not the final answer. What happened between spring-boot 2.3.4.RELEASE and 2.5.14, which cause the
primaryattribute of bean behaving differently?I add spring-orm tag, see if someone from whatever spring team could give hints. I myself will dig more too.