{"record":{"id":"e6122e06e2351367","repo":"hibernate/hibernate-orm","slug":"from-function","errorCode":"FROM_FUNCTION","errorMessage":"The JPA specification does not support functions in the from clause. Please disable the JPA query compliance if you want to use this feature.","messagePattern":"The JPA specification does not support functions in the from clause\\. Please disable the JPA query compliance if you want to use this feature\\.","errorType":"exception","errorClass":"StrictJpaComplianceViolation","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":2222,"sourceCode":"\t\tif ( getCreationOptions().useStrictJpaCompliance() ) {\n\t\t\tthrow new StrictJpaComplianceViolation(\n\t\t\t\t\t\"The JPA specification does not support subqueries in the from clause. \" +\n\t\t\t\t\t\t\t\"Please disable the JPA query compliance if you want to use this feature.\",\n\t\t\t\t\tStrictJpaComplianceViolation.Type.FROM_SUBQUERY\n\t\t\t);\n\t\t}\n\n\t\tfinal var subQuery = (SqmSubQuery<?>) ctx.subquery().accept( this );\n\t\tfinal String alias = extractAlias( ctx.variable() );\n\t\tfinal var sqmRoot = new SqmDerivedRoot<>( subQuery, alias );\n\t\tprocessingStateStack.getCurrent().getPathRegistry().register( sqmRoot );\n\t\treturn sqmRoot;\n\t}\n\n\t@Override\n\tpublic SqmRoot<?> visitRootFunction(HqlParser.RootFunctionContext ctx) {\n\t\tif ( getCreationOptions().useStrictJpaCompliance() ) {\n\t\t\tthrow new StrictJpaComplianceViolation(\n\t\t\t\t\t\"The JPA specification does not support functions in the from clause. \" +\n\t\t\t\t\t\t\t\"Please disable the JPA query compliance if you want to use this feature.\",\n\t\t\t\t\tStrictJpaComplianceViolation.Type.FROM_FUNCTION\n\t\t\t);\n\t\t}\n\n\t\tfinal var function = (SqmSetReturningFunction<?>) ctx.setReturningFunction().accept( this );\n\t\tfinal String alias = extractAlias( ctx.variable() );\n\t\tfinal var sqmRoot = new SqmFunctionRoot<>( function, alias );\n\t\tprocessingStateStack.getCurrent().getPathRegistry().register( sqmRoot );\n\t\treturn sqmRoot;\n\t}\n\n\t@Override\n\tpublic String visitVariable(HqlParser.VariableContext ctx) {\n\t\treturn extractAlias( ctx );\n\t}\n","sourceCodeStart":2204,"sourceCodeEnd":2240,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L2204-L2240","documentation":"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).","triggerScenarios":"'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.","commonSituations":"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.","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"],"exampleFix":"# before\nhibernate.jpa.compliance.query=true\nselect v from unnest(:ids) v\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) v = emf.getProperties().get(\"hibernate.jpa.compliance\");\n    return v != null && Boolean.parseBoolean(v.toString());\n}\n\nstatic boolean usesFromFunction(String hql) {\n    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();\n}\n\nif (strictQueryCompliance(emf) && usesFromFunction(hql)) { /* switch to parameterized IN or native SQL */ }","typeGuard":"static boolean isFromFunctionViolation(Throwable t) {\n    return t instanceof org.hibernate.query.sqm.StrictJpaComplianceViolation\n            && ((org.hibernate.query.sqm.StrictJpaComplianceViolation) t).getType() == org.hibernate.query.sqm.StrictJpaComplianceViolation.Type.FROM_FUNCTION;\n}","tryCatchPattern":"try {\n    return em.createQuery(\"select v from unnest(:ids) v\", Long.class).getResultList();\n} catch (org.hibernate.query.sqm.StrictJpaComplianceViolation e) {\n    return em.createQuery(\"select e.id from Employee e where e.id in :ids\", Long.class)\n             .setParameter(\"ids\", ids).getResultList(); // portable rewrite\n}","preventionTips":["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"],"tags":["hql","jpa-compliance","set-returning-function","from-clause","hibernate"],"backgroundTag":"strict-jpa-compliance-violation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}