{"record":{"id":"5daa8d37464fe33b","repo":"hibernate/hibernate-orm","slug":"unable-to-instantiate-scanner-s-5daa8d","errorCode":null,"errorMessage":"Unable to instantiate Scanner `%s`","messagePattern":"Unable to instantiate Scanner `(.+?)`","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceConfigurationDescriptor.java","lineNumber":361,"sourceCode":"\n\tprivate static Scanner determineScannerFromSetting(\n\t\t\t@Nonnull ConfigurationService configurationService,\n\t\t\t@Nonnull ClassLoaderService classLoaderService) {\n\t\tvar setting = configurationService.getSettings().get( PersistenceSettings.SCANNER );\n\t\tif ( setting == null ) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// might be any of the 3 standard forms\n\t\tif ( setting instanceof Scanner instance ) {\n\t\t\treturn instance;\n\t\t}\n\t\telse if ( setting instanceof Class<?> implClass ) {\n\t\t\ttry {\n\t\t\t\treturn (Scanner) implClass.getDeclaredConstructor().newInstance();\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new HibernateException(\n\t\t\t\t\t\tString.format( Locale.ROOT,\n\t\t\t\t\t\t\t\t\"Unable to instantiate Scanner `%s`\",\n\t\t\t\t\t\t\t\timplClass.getName()\n\t\t\t\t\t\t),\n\t\t\t\t\t\te\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tvar implClassName = setting.toString();\n\t\t\tvar implClass = classLoaderService.classForName( implClassName );\n\t\t\ttry {\n\t\t\t\treturn (Scanner) implClass.getDeclaredConstructor().newInstance();\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new HibernateException(\n\t\t\t\t\t\tString.format( Locale.ROOT,\n\t\t\t\t\t\t\t\t\"Unable to instantiate Scanner `%s`\",","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceConfigurationDescriptor.java#L343-L379","documentation":"Thrown by PersistenceConfigurationDescriptor.determineScannerFromSetting() as a HibernateException when the class configured via the hibernate.archive.scanner setting (Class-object form) cannot be instantiated with getDeclaredConstructor().newInstance(). The Scanner is what actually walks archives to locate mapping files and classes, and its configured implementation must be constructible with a no-arg constructor.","triggerScenarios":"Setting hibernate.archive.scanner to a Class that has no accessible no-arg constructor, is abstract, or whose constructor throws, during EntityManagerFactory bootstrap when the archive scanner is determined.","commonSituations":"Plugging in a custom Scanner (e.g. to integrate with Quarkus/JBoss Modules scanning) that was written for an older Hibernate SPI or requires constructor arguments; migration to Hibernate 7 where the Scanner SPI moved to org.hibernate.jpa.boot.spi and old implementations no longer fit.","solutions":["Add a public no-arg constructor to the Scanner implementation.","Recompile the custom Scanner against the current Hibernate version so it implements the current org.hibernate.jpa.boot.spi.Scanner interface.","Prefer configuring a ScanningProvider (hibernate.archive.scanning) instead of a raw Scanner in modern Hibernate.","Inspect the cause for constructor-thrown failures and fix them."],"exampleFix":"// before\npublic class ModuleScanner implements Scanner {\n    public ModuleScanner(ModuleClassLoader cl) { ... } // no no-arg ctor\n}\nprops.put(\"hibernate.archive.scanner\", ModuleScanner.class);\n\n// after\npublic class ModuleScanner implements Scanner {\n    public ModuleScanner() { }\n    void setClassLoader(ModuleClassLoader cl) { ... }\n}","handlingStrategy":"validation","validationCode":"Class<?> c = (Class<?>) settings.get(\"hibernate.archive.scanner\");\nif (c != null) {\n    if (!Scanner.class.isAssignableFrom(c)) throw new IllegalStateException(c + \" does not implement current Scanner SPI\");\n    c.getDeclaredConstructor().newInstance();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Recompile custom Scanner implementations against the Hibernate version you deploy.","Test-verify that the class is concrete, public, and no-arg constructible in a boot smoke test."],"tags":["hibernate","jpa","scanning","configuration","instantiation"],"backgroundTag":"configured-class-instantiation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}