{"record":{"id":"6b6904a314770290","repo":"hibernate/hibernate-orm","slug":"cannot-fetch-the-same-association-twice-with-a-dif","errorCode":null,"errorMessage":"Cannot fetch the same association twice with a different alias","messagePattern":"Cannot fetch the same association twice with a different alias","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java","lineNumber":214,"sourceCode":"\t\t\tSqmCreationState creationState) {\n\t\tfinal var subPathSource = lhs.getResolvedModel().getSubPathSource( name, true );\n\t\tif ( allowReuse ) {\n\t\t\tif ( !isTerminal ) {\n\t\t\t\tfor ( var sqmJoin : lhs.getSqmJoins() ) {\n\t\t\t\t\t// In order for an HQL join to be reusable, it must have the same path source,\n\t\t\t\t\tif ( sqmJoin.getModel() == subPathSource\n\t\t\t\t\t\t// and must not have a join condition.\n\t\t\t\t\t\t&& sqmJoin.getJoinPredicate() == null ) {\n\t\t\t\t\t\t// We explicitly allow reusing implicit joins of any type\n\t\t\t\t\t\treturn sqmJoin;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( fetch ) {\n\t\t\t\tfinal var compatibleFetchJoin = findCompatibleFetchJoin( lhs, subPathSource, joinType );\n\t\t\t\tif ( compatibleFetchJoin != null ) {\n\t\t\t\t\tif ( alias != null ) {\n\t\t\t\t\t\tthrow new IllegalStateException( \"Cannot fetch the same association twice with a different alias\" );\n\t\t\t\t\t}\n\t\t\t\t\treturn compatibleFetchJoin;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif ( !(subPathSource instanceof SqmJoinable) ) {\n\t\t\tthrow new SemanticException( \"Joining on basic value elements is not supported\",\n\t\t\t\t\t((SemanticQueryBuilder<?>) creationState).getQuery() );\n\t\t}\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tfinal var joinSource = (SqmJoinable<U, ?>) subPathSource;\n\t\treturn createJoin( lhs, joinType, alias, fetch, isTerminal, allowReuse, creationState, joinSource );\n\t}\n\n\tprivate static <U,V> SqmFrom<?, ?> createJoin(\n\t\t\tSqmFrom<?,U> lhs,\n\t\t\tSqmJoinType joinType,\n\t\t\tString alias,","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java#L196-L232","documentation":"Error \"Cannot fetch the same association twice with a different alias\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate API is violated.","commonSituations":"Occurs when application code or configuration does not satisfy the documented contract of the API being called.","solutions":["Fetch the association once and reuse the alias.","Remove the duplicate fetch join or give it the same alias."],"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"}