{"record":{"id":"c3a4f3e063bd9935","repo":"hibernate/hibernate-orm","slug":"serviceregistry-parent-needs-to-implement-servicer","errorCode":null,"errorMessage":"ServiceRegistry parent needs to implement ServiceRegistryImplementor","messagePattern":"ServiceRegistry parent needs to implement ServiceRegistryImplementor","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java","lineNumber":95,"sourceCode":"\tprotected AbstractServiceRegistryImpl(\n\t\t\t@Nullable ServiceRegistryImplementor parent,\n\t\t\tboolean autoCloseRegistry) {\n\n\t\tthis.parent = parent;\n\t\tthis.allowCrawling = getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );\n\t\tthis.autoCloseRegistry = autoCloseRegistry;\n\t}\n\n\tpublic AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) {\n\t\tthis( bootstrapServiceRegistry, true );\n\t}\n\n\tpublic AbstractServiceRegistryImpl(\n\t\t\tBootstrapServiceRegistry bootstrapServiceRegistry,\n\t\t\tboolean autoCloseRegistry) {\n\t\tthis.autoCloseRegistry = autoCloseRegistry;\n\t\tif ( !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor) ) {\n\t\t\tthrow new IllegalArgumentException( \"ServiceRegistry parent needs to implement ServiceRegistryImplementor\" );\n\t\t}\n\t\tthis.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;\n\t\tthis.allowCrawling = getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );\n\t}\n\n\t// For nullness checking purposes\n\tprotected void initialize() {\n\t\tif ( parent != null ) {\n\t\t\tparent.registerChild( this );\n\t\t}\n\t}\n\n\tprotected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {\n\t\tserviceBindingMap.put( initiator.getServiceInitiated(),\n\t\t\t\tnew ServiceBinding<>( this, initiator ) );\n\t}\n\n\tprotected <R extends Service> void createServiceBinding(ProvidedService<R> providedService) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java#L77-L113","documentation":"AbstractServiceRegistryImpl's constructor requires the supplied BootstrapServiceRegistry to also implement the internal SPI interface ServiceRegistryImplementor. Any custom BootstrapServiceRegistry implementation (or test mock) that only implements the public interface fails fast with IllegalArgumentException — Hibernate cannot manage parent/child registry links through an unknown implementation.","triggerScenarios":"Constructing a StandardServiceRegistryImpl (or any AbstractServiceRegistryImpl subclass) with a hand-written BootstrapServiceRegistry; passing a Mockito mock of BootstrapServiceRegistry in unit tests; wrapping the bootstrap registry in a delegating facade.","commonSituations":"Custom bootstrap plumbing in application servers or test harnesses; migration code that wraps registries; tests that try to stub registry behavior instead of using the builders.","solutions":["Obtain the bootstrap registry from BootstrapServiceRegistryBuilder.build() instead of implementing the interface yourself","If you must customize it, extend Hibernate's own bootstrap registry implementation rather than re-implementing the interface","In tests, make any mock implement ServiceRegistryImplementor or just use a real builder-built registry"],"exampleFix":"// before\nBootstrapServiceRegistry custom = new MyBootstrapRegistry(); // only implements BootstrapServiceRegistry\nnew StandardServiceRegistryImpl(custom, true); // IllegalArgumentException\n\n// after\nBootstrapServiceRegistry bootstrap = new BootstrapServiceRegistryBuilder().build();\nStandardServiceRegistry registry = new StandardServiceRegistryBuilder(bootstrap).build();","handlingStrategy":"type-guard","validationCode":"if (bootstrapServiceRegistry == null\n        || !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor)) {\n    bootstrapServiceRegistry = new BootstrapServiceRegistryBuilder().build();\n}","typeGuard":"boolean isValidBootstrapParent(BootstrapServiceRegistry bsr) {\n    return bsr instanceof ServiceRegistryImplementor;\n}","tryCatchPattern":null,"preventionTips":["Always obtain bootstrap registries from BootstrapServiceRegistryBuilder","Never implement BootstrapServiceRegistry yourself; extend Hibernate's implementation if needed","In tests, mock ServiceRegistryImplementor or use a real builder"],"tags":["service-registry","bootstrap","api-contract"],"backgroundTag":"service-registry-misconfiguration","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}