hibernate/hibernate-orm · error · StrictJpaComplianceViolation
FROM_FUNCTION
FROM_FUNCTION
Error message
The JPA specification does not support functions in the from clause. Please disable the JPA query compliance if you want to use this feature.
What it means
visitRootFunction creates a from-clause root backed by a set-returning function (unnest, generate_series, json_table, ...) and first checks strict JPQL query compliance. JPA has no set-returning functions in the from clause, so with 'hibernate.jpa.compliance.query=true' the query is rejected (StrictJpaComplianceViolation.Type.FROM_FUNCTION).
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:2222
if ( getCreationOptions().useStrictJpaCompliance() ) {
throw new StrictJpaComplianceViolation(
"The JPA specification does not support subqueries in the from clause. " +
"Please disable the JPA query compliance if you want to use this feature.",
StrictJpaComplianceViolation.Type.FROM_SUBQUERY
);
}
final var subQuery = (SqmSubQuery<?>) ctx.subquery().accept( this );
final String alias = extractAlias( ctx.variable() );
final var sqmRoot = new SqmDerivedRoot<>( subQuery, alias );
processingStateStack.getCurrent().getPathRegistry().register( sqmRoot );
return sqmRoot;
}
@Override
public SqmRoot<?> visitRootFunction(HqlParser.RootFunctionContext ctx) {
if ( getCreationOptions().useStrictJpaCompliance() ) {
throw new StrictJpaComplianceViolation(
"The JPA specification does not support functions in the from clause. " +
"Please disable the JPA query compliance if you want to use this feature.",
StrictJpaComplianceViolation.Type.FROM_FUNCTION
);
}
final var function = (SqmSetReturningFunction<?>) ctx.setReturningFunction().accept( this );
final String alias = extractAlias( ctx.variable() );
final var sqmRoot = new SqmFunctionRoot<>( function, alias );
processingStateStack.getCurrent().getPathRegistry().register( sqmRoot );
return sqmRoot;
}
@Override
public String visitVariable(HqlParser.VariableContext ctx) {
return extractAlias( ctx );
}
View on GitHub (pinned to fad1729dce)
Solutions
- Disable the query compliance flag: 'hibernate.jpa.compliance.query=false'
- Rewrite using a plain cross join to a real table, a member-of collection predicate, or parameters expanded client-side
- Fall back to a native query for the set-returning part
Example fix
# before hibernate.jpa.compliance.query=true select v from unnest(:ids) v # 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());
}
static boolean usesFromFunction(String hql) {
return java.util.regex.Pattern.compile("\\bfrom\\s+(unnest|generate_series|json_table|jsonb_array_elements|values)\\s*\\(", java.util.regex.Pattern.CASE_INSENSITIVE).matcher(hql).find();
}
if (strictQueryCompliance(emf) && usesFromFunction(hql)) { /* switch to parameterized IN or native SQL */ } Type guard
static boolean isFromFunctionViolation(Throwable t) {
return t instanceof org.hibernate.query.sqm.StrictJpaComplianceViolation
&& ((org.hibernate.query.sqm.StrictJpaComplianceViolation) t).getType() == org.hibernate.query.sqm.StrictJpaComplianceViolation.Type.FROM_FUNCTION;
} Try / catch
try {
return em.createQuery("select v from unnest(:ids) v", Long.class).getResultList();
} catch (org.hibernate.query.sqm.StrictJpaComplianceViolation e) {
return em.createQuery("select e.id from Employee e where e.id in :ids", Long.class)
.setParameter("ids", ids).getResultList(); // portable rewrite
} Prevention
- Gate set-returning-function queries behind a capability check on the compliance setting
- Keep a native-SQL variant for table functions that must run in strict deployments
- Include compliance-on and compliance-off profiles in integration tests
When it happens
Trigger: 'select u.* from unnest(:ids) u' or 'from generate_series(1, 10) g' executed with hibernate.jpa.compliance.query=true; Hibernate 6.6+/7 set-returning function features used in a compliance-strict factory.
Common situations: Compliance flags turned on globally while code relies on modern Hibernate HQL extensions; upgrading Hibernate and adopting table functions in projects whose compliance template was written years earlier.
Related errors
- UNMAPPED_POLYMORPHISM
- NON_ENTITY_NAME
- Could not resolve root entity '${name}'
- FROM_SUBQUERY
- ALIASED_FETCH_JOIN
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e6122e06e2351367.
Report an issue: GitHub.