{"record":{"id":"036f9613eb71ff6a","repo":"hibernate/hibernate-orm","slug":"mapping-s-not-found-s","errorCode":null,"errorMessage":"Mapping (%s) not found : %s","messagePattern":"Mapping \\((.+?)\\) not found : (.+?)","errorType":"exception","errorClass":"MappingNotFoundException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/FileXmlSource.java","lineNumber":39,"sourceCode":" *\n * @see MappingBinder\n *\n * @author Steve Ebersole\n */\npublic class FileXmlSource {\n\t/**\n\t * Create a mapping {@linkplain Binding binding} from a File reference.\n\t */\n\tpublic static Binding<? extends JaxbBindableMappingDescriptor> fromFile(\n\t\t\tFile file,\n\t\t\tMappingBinder mappingBinder) {\n\t\tfinal String filePath = file.getPath();\n\t\tJAXB_LOGGER.tracef( \"Reading mappings from file: %s\", filePath );\n\n\t\tfinal var origin = new Origin( SourceType.FILE, filePath );\n\n\t\tif ( !file.exists() ) {\n\t\t\tthrow new MappingNotFoundException( origin );\n\t\t}\n\n\t\tfinal FileInputStream fis;\n\t\ttry {\n\t\t\tfis = new FileInputStream( file );\n\t\t}\n\t\tcatch ( FileNotFoundException e ) {\n\t\t\tthrow new MappingNotFoundException( e, origin );\n\t\t}\n\n\t\treturn InputStreamXmlSource.fromStream( fis, origin, true, mappingBinder );\n\t}\n}\n","sourceCodeStart":21,"sourceCodeEnd":53,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/FileXmlSource.java#L21-L53","documentation":"FileXmlSource.fromFile was asked to read a mapping from a File whose exists() check returned false, so it threw MappingNotFoundException ('Mapping (%s) not found : %s') with a FILE-type Origin. The path simply does not point at an existing file from the JVM's perspective.","triggerScenarios":"metadataSources.addFile(path) / equivalent with a wrong relative path: relative paths resolve against the process working directory, not the classpath or project root; also moved/renamed mapping files.","commonSituations":"Working-directory differences between IDE, test runner, and production; paths like 'src/main/resources/...' that only work at build time; files packaged into jars being referenced as Files.","solutions":["Print new File(path).getAbsolutePath() to see where the JVM is actually looking","Use an absolute path or construct it from a known root (user.dir, config property)","If the mapping is a classpath resource, use addResource('com/acme/User.hbm.xml') instead of a File","If it is inside a jar, use the jar-entry source, not File"],"exampleFix":"// before: relative path, wrong cwd\nsources.addFile(\"src/main/resources/com/acme/User.hbm.xml\");\n\n// after: classpath resource\nsources.addResource(\"com/acme/User.hbm.xml\");","handlingStrategy":"validation","validationCode":"// resolve and check the mapping file before registering it\nFile f = new File(path);\nif (!f.exists()) {\n    throw new IllegalArgumentException(\n        \"Mapping not found: \" + path + \" (resolved to \" + f.getAbsolutePath() + \")\");\n}\nmetadataSources.addFile(f.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n    metadataSources.addFile(path);\n} catch (MappingNotFoundException e) {\n    // Origin in the exception names the exact path that failed; log it and fix the path\n    log.error(\"Missing mapping: {}\", e.getMessage());\n    throw e;\n}","preventionTips":["Prefer addResource with classpath paths over addFile with filesystem paths","Log the resolved absolute path during bootstrap configuration","Centralize mapping path construction in one configuration class"],"tags":["hibernate","mapping-file","file-not-found","bootstrap"],"backgroundTag":"mapping-file-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}