{"record":{"id":"842ff0b048cc334c","repo":"hibernate/hibernate-orm","slug":"no-root-entity-with-alias-s","errorCode":null,"errorMessage":"No root entity with alias %s","messagePattern":"No root entity with alias (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/AbstractSqmSelectQuery.java","lineNumber":290,"sourceCode":"\t\tfinal var rootList = getQuerySpec().getRootList();\n\t\tif ( rootList.size() <= position ) {\n\t\t\tthrow new IllegalArgumentException( \"Not enough root entities\" );\n\t\t}\n\t\treturn castRoot( rootList.get( position ), type );\n\t}\n\n\t/**\n\t * @see org.hibernate.query.criteria.JpaCriteriaQuery#getRoot(String, Class)\n\t */\n\t@Nonnull\n\tpublic <E> JpaRoot<? extends E> getRoot(String alias, Class<E> type) {\n\t\tfor ( var root : getQuerySpec().getRootList() ) {\n\t\t\tfinal String rootAlias = root.getAlias();\n\t\t\tif ( rootAlias != null && rootAlias.equals( alias ) ) {\n\t\t\t\treturn castRoot( root, type );\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException( \"No root entity with alias \" + alias );\n\t}\n\n\tprivate static <E> JpaRoot<? extends E> castRoot(JpaRoot<?> root, Class<E> type) {\n\t\tfinal var rootEntityType = root.getJavaType();\n\t\tif ( rootEntityType == null ) {\n\t\t\tthrow new AssertionFailure( \"Java type of root entity was null\" );\n\t\t}\n\t\tif ( !type.isAssignableFrom( rootEntityType ) ) {\n\t\t\tthrow new IllegalArgumentException( \"Root entity of type '\" + rootEntityType.getTypeName()\n\t\t\t\t\t\t\t\t\t\t\t\t+ \"' did not have the given type '\" + type.getTypeName() + \"'\");\n\t\t}\n\t\t@SuppressWarnings(\"unchecked\") // safe, we just checked\n\t\tfinal var result = (JpaRoot<? extends E>) root;\n\t\treturn result;\n\t}\n\n\t@Nonnull\n\t@Override","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/AbstractSqmSelectQuery.java#L272-L308","documentation":"Error \"No root entity with alias %s\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A Criteria API query calls a method that looks up a root entity by alias (e.g. AbstractSqmSelectQuery#getRoot(alias)) and no root was registered with that alias.","commonSituations":"Typo in the alias string, or the alias was never assigned via Root.alias() before lookup.","solutions":["Check the alias passed to the lookup: it must exactly match the alias given to a root in the FROM clause (aliases are case-sensitive).","List the root entities of the query first (e.g. via getRootList()/getRoots()) and use one of their aliases.","If the root was created without an explicit alias, set one when creating the root (criteria.from(Entity.class).alias(\"e\")) and use that alias here."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}