{"record":{"id":"635e21c559029b25","repo":"quarkusio/quarkus","slug":"failed-to-read-class-bytes-for-classname-cla","errorCode":null,"errorMessage":"Failed to read class bytes for '${className}', class not present in class loaders: ${classLoader1}, ${classLoader2}","messagePattern":"Failed to read class bytes for '(.+?)', class not present in class loaders: (.+?), (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java","lineNumber":1280,"sourceCode":"                    .setClassToTransform(i)\n                    .setVisitorFunction(hibernateEntityEnhancer)\n                    .setCacheable(true).build());\n        }\n        Set<String> additionalClassNames = new HashSet<>();\n        for (AdditionalJpaModelBuildItem additionalJpaModel : additionalJpaModelBuildItems) {\n            additionalClassNames.add(additionalJpaModel.getClassName());\n        }\n        for (io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem additionalJpaModel : deprecatedAdditionalJpaModelBuildItems) {\n            additionalClassNames.add(additionalJpaModel.getClassName());\n        }\n        for (String className : additionalClassNames) {\n            try {\n                byte[] bytes = IoUtil.readClassAsBytes(HibernateOrmProcessor.class.getClassLoader(), className);\n                if (bytes == null) {\n                    bytes = IoUtil.readClassAsBytes(Thread.currentThread().getContextClassLoader(), className);\n                }\n                if (bytes == null) {\n                    throw new RuntimeException(\"Failed to read class bytes for '\" + className\n                            + \"', class not present in class loaders: \"\n                            + HibernateOrmProcessor.class.getClassLoader()\n                            + \", \" + Thread.currentThread().getContextClassLoader());\n                }\n                byte[] enhanced = hibernateEntityEnhancer.enhance(className, bytes);\n                additionalClasses.produce(new GeneratedClassBuildItem(false, className, enhanced != null ? enhanced : bytes));\n            } catch (IOException e) {\n                throw new RuntimeException(\"Failed to read Model class\", e);\n            }\n        }\n    }\n\n    @BuildStep\n    public JpaModelPerPersistenceUnitBuildItem buildJpaModelPerPersistenceUnit(HibernateOrmConfig hibernateOrmConfig,\n            List<AdditionalJpaModelBuildItem> additionalJpaModelBuildItems, JpaModelBuildItem jpaModel,\n            CombinedIndexBuildItem indexBuildItem) {\n        IndexView index = indexBuildItem.getIndex();\n        Map<String, JpaPersistenceUnitModel> modelPerPersistenceUnit = new HashMap<>();","sourceCodeStart":1262,"sourceCodeEnd":1298,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java#L1262-L1298","documentation":"During bytecode processing of model classes (entity enhancement), the processor reads the class bytes from the processor's classloader, falling back to the context classloader. If neither can provide the bytes, it throws a RuntimeException naming the class and both classloaders.","triggerScenarios":"IoUtil.readClassAsBytes returns null for a class name in the JPA model from both HibernateOrmProcessor.class.getClassLoader() and the thread context classloader while enhancing/listing model classes.","commonSituations":"Entity classes generated at build time but not yet on the processor classloader; classes referenced by entities living in a jar excluded from the application archive; unusual classloading setups in custom packaging.","solutions":["Ensure all entity/model classes are part of the application archive and its dependencies (not generated post-index or excluded)","Verify the dependency containing the class is a normal application dependency, not provided/optional with wrong scope","Clean and rebuild (mvn clean install) to remove stale build artifacts"],"exampleFix":"// pom.xml\n// before\n<dependency>\n  <groupId>com.acme</groupId><artifactId>entities</artifactId><scope>provided</scope>\n</dependency>\n// after\n<dependency>\n  <groupId>com.acme</groupId><artifactId>entities</artifactId>\n</dependency>","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(\"com.acme.MyEntity\", false,\n    Thread.currentThread().getContextClassLoader());\nif (c == null) { throw new IllegalStateException(\"Model class not on app classpath\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all entity classes as regular application dependencies (not provided/optional)","Avoid excluding entity jars from the Quarkus application archive","Rebuild with mvn clean install when classes were recently moved between modules"],"tags":["classloading","hibernate-orm","bytecode-enhancement"],"backgroundTag":"class-not-found-in-classloader","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}