{"record":{"id":"e55becc2542a093f","repo":"hibernate/hibernate-orm","slug":"non-entity-name","errorCode":"NON_ENTITY_NAME","errorMessage":"Encountered the use of a non entity name [${entityName}], but strict JPQL compliance was requested which doesn't allow this","messagePattern":"Encountered the use of a non entity name \\[(.+?)\\], but strict JPQL compliance was requested which doesn't allow this","errorType":"exception","errorClass":"StrictJpaComplianceViolation","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":2041,"sourceCode":"\tpublic String visitNakedIdentifier(HqlParser.NakedIdentifierContext ctx) {\n\t\tfinal var node = (TerminalNode) ctx.getChild( 0 );\n\t\tfinal String text = node.getText();\n\t\treturn node.getSymbol().getType() == QUOTED_IDENTIFIER\n\t\t\t\t? unquoteIdentifier( text )\n\t\t\t\t: text;\n\t}\n\n\t@Override\n\tpublic EntityDomainType<?> visitEntityName(HqlParser.EntityNameContext parserEntityName) {\n\t\tfinal String entityName = getEntityName( parserEntityName );\n\t\tfinal var entityReference = getJpaMetamodel().getHqlEntityReference( entityName );\n\t\tif ( entityReference == null ) {\n\t\t\tthrow new UnknownEntityException( \"Could not resolve target entity '\" + entityName + \"'\", entityName );\n\t\t}\n\t\tcheckFQNEntityNameJpaComplianceViolationIfNeeded( entityName, entityReference );\n\t\tif ( entityReference instanceof SqmPolymorphicRootDescriptor<?>\n\t\t\t\t&& getCreationOptions().useStrictJpaCompliance() ) {\n\t\t\tthrow new StrictJpaComplianceViolation(\n\t\t\t\t\t\"Encountered the use of a non entity name [\" + entityName + \"], \" +\n\t\t\t\t\t\t\t\"but strict JPQL compliance was requested which doesn't allow this\",\n\t\t\t\t\tStrictJpaComplianceViolation.Type.NON_ENTITY_NAME\n\t\t\t);\n\t\t}\n\t\treturn entityReference;\n\t}\n\n\t@Override\n\tpublic SqmFromClause visitFromClause(HqlParser.FromClauseContext parserFromClause) {\n\t\tfinal var roots = parserFromClause.entityWithJoins();\n\t\tfinal var fromClause = new SqmFromClause( roots.size() );\n\n\t\t//have to do this here because visiting the from-elements needs it\n\t\tcurrentQuerySpec().setFromClause( fromClause );\n\n\t\tif ( creationOptions.useStrictJpaCompliance() && roots.size() > 1 ) {\n\t\t\t// for multiple roots, JPA says that the secondary roots should be","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L2023-L2059","documentation":"The name resolved to a Hibernate polymorphic reference (SqmPolymorphicRootDescriptor - e.g. 'java.lang.Object' or a package-namespace name covering several entities) rather than a single mapped entity. With strict JPQL query compliance enabled (hibernate.jpa.compliance.query), Hibernate rejects such non-entity names in this position (StrictJpaComplianceViolation.Type.NON_ENTITY_NAME).","triggerScenarios":"Strict compliance enabled plus an entity-name position using a polymorphic name, e.g. 'select treat(o as java.lang.Object)', type(...) comparisons against a namespace name, or entity references resolved through package-level polymorphism.","commonSituations":"A shared compliance template or platform default turns on hibernate.jpa.compliance=true; teams using Hibernate-specific polymorphic HQL then hit violations after the flag is enabled.","solutions":["Use a concrete mapped entity name in the query","Disable the query-specific compliance flag: 'hibernate.jpa.compliance.query=false' (keep other compliance flags on if needed)","If global JPA compliance is mandatory, keep every query strictly JPQL: no polymorphic or namespace names"],"exampleFix":"# before\nhibernate.jpa.compliance=true\n\n# after\nhibernate.jpa.compliance.query=false","handlingStrategy":"fallback","validationCode":"static boolean strictQueryCompliance(EntityManagerFactory emf) {\n    Object v = emf.getProperties().get(\"hibernate.jpa.compliance.query\");\n    if (v == null) {\n        v = emf.getProperties().get(\"hibernate.jpa.compliance\");\n    }\n    return v != null && Boolean.parseBoolean(v.toString());\n}\n\n// before using polymorphic names\nif (strictQueryCompliance(emf)) { /* use concrete entity names only */ }","typeGuard":"static boolean isStrictJpaViolation(Throwable t) {\n    return t instanceof org.hibernate.query.sqm.StrictJpaComplianceViolation;\n}","tryCatchPattern":"try {\n    return em.createQuery(hql, Object.class).getResultList();          // Hibernate-specific query\n} catch (org.hibernate.query.sqm.StrictJpaComplianceViolation e) {\n    return em.createQuery(jpqlFallbackHql, Object.class).getResultList(); // strictly-JPQL rewrite\n}","preventionTips":["Document which queries rely on Hibernate extensions before enabling compliance flags","Set 'hibernate.jpa.compliance.query' explicitly instead of inheriting global compliance blindly","Keep a compliance test profile that runs the full query set with the flag on"],"tags":["hql","jpa-compliance","polymorphism","hibernate"],"backgroundTag":"strict-jpa-compliance-violation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}