{"record":{"id":"1f85aa4759d5f281","repo":"hibernate/hibernate-orm","slug":"no-filter-condition-found-for-filter-s-associat","errorCode":null,"errorMessage":"No filter condition found for filter [%s] associated with many-to-many [%s]","messagePattern":"No filter condition found for filter \\[(.+?)\\] associated with many-to-many \\[(.+?)\\]","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java","lineNumber":3243,"sourceCode":"\t\t\t\tbindManyToManyFilter( mappingDocument, collectionBinding, filterSource );\n\t\t\t}\n\t\t}\n\n\t\tprivate void bindManyToManyFilter(\n\t\t\t\tMappingDocument mappingDocument, Collection collectionBinding, FilterSource filterSource) {\n\t\t\tfinal String name = filterSource.getName();\n\t\t\tif ( name == null ) {\n\t\t\t\tif ( BOOT_LOGGER.isTraceEnabled() ) {\n\t\t\t\t\tBOOT_LOGGER.tracef(\n\t\t\t\t\t\t\t\"Encountered filter with no name associated with many-to-many [%s]; skipping\",\n\t\t\t\t\t\t\tgetPluralAttributeSource().getAttributeRole().getFullPath()\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfinal String condition = filterSource.getCondition();\n\t\t\t\tif ( condition == null ) {\n\t\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\t\"No filter condition found for filter [%s] associated with many-to-many [%s]\"\n\t\t\t\t\t\t\t\t\t.formatted( name, getPluralAttributeSource().getAttributeRole().getFullPath() ),\n\t\t\t\t\t\t\tmappingDocument.getOrigin()\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif ( BOOT_LOGGER.isTraceEnabled() ) {\n\t\t\t\t\tBOOT_LOGGER.tracef(\n\t\t\t\t\t\t\t\"Applying many-to-many filter [%s] as [%s] to collection [%s]\",\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tcondition,\n\t\t\t\t\t\t\tgetPluralAttributeSource().getAttributeRole().getFullPath()\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcollectionBinding.addManyToManyFilter(\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tcondition,\n\t\t\t\t\t\tfilterSource.shouldAutoInjectAliases(),\n\t\t\t\t\t\tfilterSource.getAliasToTableMap(),","sourceCodeStart":3225,"sourceCodeEnd":3261,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L3225-L3261","documentation":"When binding filters attached to a many-to-many element, each named filter must resolve to a SQL condition - either the condition= attribute on the <filter> element itself or the default condition declared in the matching <filter-def>. If the filter has a name but no resolvable condition, Hibernate cannot build the SQL restriction and fails before the SessionFactory is created.","triggerScenarios":"<filter name='active'/> inside a <many-to-many> element when no <filter-def name='active' condition='...'> exists anywhere in the loaded mappings and the <filter> element itself has no condition attribute.","commonSituations":"The <filter-def> lives in another mapping file that is not added to the Configuration; the filter name is misspelled so no filter-def matches; assuming a condition-less filter is a no-op.","solutions":["Add condition='...' to the <filter> element itself","Or declare (or fix) the matching <filter-def> with a default condition and ensure its file is loaded","Check the filter name spelling against the filter-def name"],"exampleFix":"// before (no filter-def anywhere)\n<many-to-many class='Role'>\n    <filter name='active'/>\n</many-to-many>\n\n// after\n<filter-def name='active' condition='deleted = false'/>\n...\n<many-to-many class='Role'>\n    <filter name='active' condition='deleted = false'/>\n</many-to-many>","handlingStrategy":"validation","validationCode":"// every <filter name='x'> must find a condition locally or in a <filter-def name='x'>\nMap<String, String> defs = new HashMap<>();\nNodeList fd = doc.getElementsByTagName(\"filter-def\");\nfor (int i = 0; i < fd.getLength(); i++) { Element d = (Element) fd.item(i); defs.put(d.getAttribute(\"name\"), d.getAttribute(\"condition\")); }\nNodeList filters = doc.getElementsByTagName(\"filter\");\nfor (int i = 0; i < filters.getLength(); i++) {\n    Element f = (Element) filters.item(i);\n    String name = f.getAttribute(\"name\");\n    boolean local = f.getAttributeNode(\"condition\") != null && !f.getAttribute(\"condition\").isBlank();\n    if (!local && !defs.containsKey(name)) {\n        throw new IllegalStateException(\"filter '\" + name + \"' has no condition and no filter-def\");\n    }\n}","typeGuard":null,"tryCatchPattern":"catch (MappingException e) at bootstrap; the message names the filter and the many-to-many collection. Add condition= to that <filter> or load a <filter-def> providing a default condition.","preventionTips":["Define every filter name in exactly one <filter-def> with a default condition","Ensure the file containing filter-defs is always registered with the Configuration","Keep filter names in constants shared between code and mappings"],"tags":["hibernate","hbm-mapping","filter-def","many-to-many","filter-condition"],"backgroundTag":"missing-filter-condition","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}