{"record":{"id":"abf5fe22a1b3d316","repo":"hibernate/hibernate-orm","slug":"unable-to-obtain-input-stream-from","errorCode":null,"errorMessage":"Unable to obtain input stream from [{}]","messagePattern":"Unable to obtain input stream from \\[(.+?)\\]","errorType":"exception","errorClass":"PersistenceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java","lineNumber":326,"sourceCode":"\t\t\t}\n\t\t\tthrow new PersistenceException( \"Unknown persistence unit transaction type : \" + value );\n\t\t}\n\t}\n\n\tprivate JaxbPersistenceImpl loadUrlWithJaxb(URL xmlUrl) {\n\t\tfinal String resourceName = xmlUrl.toExternalForm();\n\t\ttry {\n\t\t\tvar connection = xmlUrl.openConnection();\n\t\t\t// avoid JAR locking on Windows and Tomcat\n\t\t\tconnection.setUseCaches( false );\n\t\t\ttry ( var inputStream = connection.getInputStream() ) {\n\t\t\t\treturn new ConfigurationBinder( classLoaderService )\n\t\t\t\t\t\t.bind( new StreamSource( inputStream ),\n\t\t\t\t\t\t\t\tnew Origin( SourceType.URL, resourceName ) )\n\t\t\t\t\t\t.getRoot();\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new PersistenceException( \"Unable to obtain input stream from [\" + resourceName + \"]\", e );\n\t\t\t}\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new PersistenceException( \"Unable to access [\" + resourceName + \"]\", e );\n\t\t}\n\t}\n\n}\n","sourceCodeStart":308,"sourceCodeEnd":335,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java#L308-L335","documentation":"Thrown by PersistenceXmlParser.loadUrlWithJaxb() as a PersistenceException when URL.openConnection() succeeded but connection.getInputStream() raised an IOException while reading a persistence.xml resource. The resource URL resolved, but the actual stream could not be opened - the connection to the resource broke at read time. The resource name is included in the message.","triggerScenarios":"Opening the persistence.xml URL during parsing where the jar/file was deleted, swapped, or locked between URL resolution and stream read; a jar entry that reports a size but cannot be read (corrupt zip); permission denied on the file; connection refused for an http-hosted descriptor.","commonSituations":"Hot redeploy/repackaging on Windows where the old jar is locked or removed mid-boot; exploded deployments whose META-INF/persistence.xml permissions changed; partially uploaded or corrupted jar files; Tomcat/JBoss wars being modified while Hibernate scans them.","solutions":["Verify the resource named in the message exists and is readable at bootstrap time (open it manually from the same classloader).","Rebuild/redeploy the artifact to eliminate a corrupted or truncated jar.","On Windows/Tomcat, ensure no process locks the jar (setUseCaches(false) is already applied by Hibernate) and stop parallel redeployments during boot.","If the file lives on a remote URL, check network availability and server logs for the refused read."],"exampleFix":"// before: jar replaced while app boots\n// after: deploy atomically - build the war fully, then swap it in one step\n// e.g. cp app.war.new tmp/ && mv tmp/app.war.new webapps/app.war","handlingStrategy":"try-catch","validationCode":"// pre-open the descriptor from the same classloader before boot\nURL url = Thread.currentThread().getContextClassLoader().getResource(\"META-INF/persistence.xml\");\nif (url == null) throw new IllegalStateException(\"persistence.xml not found\");\ntry (InputStream in = url.openConnection().getInputStream()) { in.read(); } // fail with your own error","typeGuard":null,"tryCatchPattern":"catch (PersistenceException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Unable to obtain input stream\")) {\n        log.error(\"persistence.xml unreadable (locked/removed/corrupt jar): {}\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Deploy archives atomically: build the full artifact, then swap it in one step.","Keep classpath entries immutable while the application boots; no parallel repackaging."],"tags":["hibernate","jpa","persistence-xml","io","deployment","resource-loading"],"backgroundTag":"resource-read-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}