hibernate/hibernate-orm · error · StrictJpaComplianceViolation
NON_ENTITY_NAME
NON_ENTITY_NAME
Error message
Encountered the use of a non entity name [${entityName}], but strict JPQL compliance was requested which doesn't allow this What it means
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).
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:2041
public String visitNakedIdentifier(HqlParser.NakedIdentifierContext ctx) {
final var node = (TerminalNode) ctx.getChild( 0 );
final String text = node.getText();
return node.getSymbol().getType() == QUOTED_IDENTIFIER
? unquoteIdentifier( text )
: text;
}
@Override
public EntityDomainType<?> visitEntityName(HqlParser.EntityNameContext parserEntityName) {
final String entityName = getEntityName( parserEntityName );
final var entityReference = getJpaMetamodel().getHqlEntityReference( entityName );
if ( entityReference == null ) {
throw new UnknownEntityException( "Could not resolve target entity '" + entityName + "'", entityName );
}
checkFQNEntityNameJpaComplianceViolationIfNeeded( entityName, entityReference );
if ( entityReference instanceof SqmPolymorphicRootDescriptor<?>
&& getCreationOptions().useStrictJpaCompliance() ) {
throw new StrictJpaComplianceViolation(
"Encountered the use of a non entity name [" + entityName + "], " +
"but strict JPQL compliance was requested which doesn't allow this",
StrictJpaComplianceViolation.Type.NON_ENTITY_NAME
);
}
return entityReference;
}
@Override
public SqmFromClause visitFromClause(HqlParser.FromClauseContext parserFromClause) {
final var roots = parserFromClause.entityWithJoins();
final var fromClause = new SqmFromClause( roots.size() );
//have to do this here because visiting the from-elements needs it
currentQuerySpec().setFromClause( fromClause );
if ( creationOptions.useStrictJpaCompliance() && roots.size() > 1 ) {
// for multiple roots, JPA says that the secondary roots should beView on GitHub (pinned to fad1729dce)
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
Example fix
# before hibernate.jpa.compliance=true # after hibernate.jpa.compliance.query=false
Defensive patterns
Strategy: fallback
Validate before calling
static boolean strictQueryCompliance(EntityManagerFactory emf) {
Object v = emf.getProperties().get("hibernate.jpa.compliance.query");
if (v == null) {
v = emf.getProperties().get("hibernate.jpa.compliance");
}
return v != null && Boolean.parseBoolean(v.toString());
}
// before using polymorphic names
if (strictQueryCompliance(emf)) { /* use concrete entity names only */ } Type guard
static boolean isStrictJpaViolation(Throwable t) {
return t instanceof org.hibernate.query.sqm.StrictJpaComplianceViolation;
} Try / catch
try {
return em.createQuery(hql, Object.class).getResultList(); // Hibernate-specific query
} catch (org.hibernate.query.sqm.StrictJpaComplianceViolation e) {
return em.createQuery(jpqlFallbackHql, Object.class).getResultList(); // strictly-JPQL rewrite
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- UNMAPPED_POLYMORPHISM
- Strict JPA query language compliance was violated: use of im
- Implicitly-polymorphic domain path in subquery '${name}'
- FROM_SUBQUERY
- FROM_FUNCTION
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e55becc2542a093f.
Report an issue: GitHub.