{"record":{"id":"30c034fff7322c95","repo":"hibernate/hibernate-orm","slug":"manytomany-or-elementcollection-defining-filter","errorCode":null,"errorMessage":"@ManyToMany or @ElementCollection defining filter or where without join fetching not valid within collection using join fetching[<role>]","messagePattern":"@ManyToMany or @ElementCollection defining filter or where without join fetching not valid within collection using join fetching\\[<role>\\]","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java","lineNumber":2705,"sourceCode":"\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate static String extractHqlOrderBy(OrderBy jpaOrderBy) {\n\t\treturn jpaOrderBy != null\n\t\t\t\t// Null not possible. In case of empty expression, apply default ordering.\n\t\t\t\t? jpaOrderBy.value()\n\t\t\t\t// @OrderBy not found.\n\t\t\t\t: null;\n\t}\n\n\tprivate static void checkFilterConditions(Collection collection) {\n\t\t//for now it can't happen, but sometime soon...\n\t\tif ( ( !collection.getFilters().isEmpty() || isNotBlank( collection.getWhere() ) )\n\t\t\t\t&& collection.getFetchStyle() == FetchStyle.JOIN\n\t\t\t\t&& !( collection.getElement() instanceof SimpleValue ) //SimpleValue (CollectionOfElements) are always SELECT but it does not matter\n\t\t\t\t&& collection.getElement().getFetchStyle() != FetchStyle.JOIN ) {\n\t\t\tthrow new MappingException(\n\t\t\t\t\t\"@ManyToMany or @ElementCollection defining filter or where without join fetching \"\n\t\t\t\t\t\t\t+ \"not valid within collection using join fetching[\" + collection.getRole() + \"]\"\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate static void checkConsistentColumnMutability(Collection collection) {\n\t\tcheckConsistentColumnMutability( collection.getRole(), collection.getKey() );\n\t\tcheckConsistentColumnMutability( collection.getRole(), collection.getElement() );\n\t}\n\n\tprivate static void checkConsistentColumnMutability(String collectionRole, Value value) {\n\t\tBoolean readOnly = null;\n\t\tfor ( int i = 0; i < value.getColumnSpan(); i++ ) {\n\t\t\tfinal boolean insertable = value.isColumnInsertable( i );\n\t\t\tif ( insertable != value.isColumnUpdateable( i ) ) {\n\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\"Join column '\" + value.getColumns().get( i ).getName() + \"' on collection property '\"","sourceCodeStart":2687,"sourceCodeEnd":2723,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java#L2687-L2723","documentation":"Error \"@ManyToMany or @ElementCollection defining filter or where without join fetching not valid within collection using join fetching[<role>]\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A @Filter/@FilterJoinTable usage references an undefined filter or has no usable condition.","commonSituations":"@Filter used without a matching @FilterDef, a misspelled filter name, or neither the usage nor the FilterDef supplying a default condition.","solutions":["Remove the filter/where clause or change the fetching strategy so join fetching is not combined with filter/where on this collection."],"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"}