{"record":{"id":"d19b979c17fea98d","repo":"hibernate/hibernate-orm","slug":"sessionfactory-uuid-cannot-be-null","errorCode":null,"errorMessage":"SessionFactory UUID cannot be null","messagePattern":"SessionFactory UUID cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryRegistry.java","lineNumber":83,"sourceCode":"\t}\n\n\t/**\n\t * Adds a SessionFactory to the registry\n\t *\n\t * @param uuid The uuid under which to register the SessionFactory\n\t * @param name The optional name under which to register the SessionFactory\n\t * @param jndiName An optional name to use for binding the SessionFactory into JNDI\n\t * @param instance The SessionFactory instance\n\t * @param jndiService The JNDI service, so we can register a listener if name is a JNDI name\n\t */\n\tpublic void addSessionFactory(\n\t\t\tString uuid,\n\t\t\tString name,\n\t\t\tString jndiName,\n\t\t\tSessionFactoryImplementor instance,\n\t\t\tJndiService jndiService) {\n\t\tif ( uuid == null ) {\n\t\t\tthrow new IllegalArgumentException( \"SessionFactory UUID cannot be null\" );\n\t\t}\n\n\t\tREGISTRY_LOGGER.registeringSessionFactory( uuid, name == null ? \"<unnamed>\" : name );\n\t\tsessionFactoryMap.put( uuid, instance );\n\t\tif ( name != null ) {\n\t\t\tnameUuidXref.put( name, uuid );\n\t\t}\n\n\t\tif ( jndiName == null ) {\n\t\t\tREGISTRY_LOGGER.notBindingSessionFactory();\n\t\t\treturn;\n\t\t}\n\n\t\tbindToJndi( jndiName, instance, jndiService );\n\t}\n\n\tprivate void bindToJndi(String jndiName, SessionFactoryImplementor instance, JndiService jndiService) {\n\t\ttry {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryRegistry.java#L65-L101","documentation":"SessionFactoryRegistry.addSessionFactory keys factories by uuid and treats null as a programmer error: IllegalArgumentException is thrown before any registration. In normal bootstrap the uuid comes from SessionFactoryOptions and is generated automatically, so hitting this means custom bootstrap code constructed or registered a factory implementation without a uuid.","triggerScenarios":"Calling SessionFactoryRegistry.INSTANCE.addSessionFactory(null, ...) from a custom SessionFactoryImplementor or custom bootstrap path; tests/fakes that register stand-in factories; code building SessionFactoryOptions manually and leaving the uuid unset.","commonSituations":"Custom SessionFactoryImplementor implementations (rare, e.g. wrappers/proxies passed to the registry); test harnesses that fake the registry; framework integrations that bypass the standard MetadataBuilder/SessionFactoryBuilder pipeline.","solutions":["Build factories through the standard pipeline (Configuration.buildSessionFactory() or SessionFactoryBuilder) so the uuid is generated for you","If you construct SessionFactoryOptions yourself, always set a uuid (options.uuid(UUID.randomUUID().toString())) before addSessionFactory","Add an assertion in custom bootstrap code: Objects.requireNonNull(options.getUuid()) with a clear message","For wrapper factories, delegate to the wrapped factory's uuid instead of inventing a null one"],"exampleFix":"// before\nSessionFactoryRegistry.INSTANCE.addSessionFactory(null, \"myFactory\", null, myFactoryImpl, null);\n// IllegalArgumentException\n\n// after\nString uuid = myFactoryImpl.getUuid() != null\n        ? myFactoryImpl.getUuid()\n        : UUID.randomUUID().toString();\nSessionFactoryRegistry.INSTANCE.addSessionFactory(uuid, \"myFactory\", null, myFactoryImpl, null);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(uuid, \"SessionFactory UUID cannot be null — \"\n        + \"generate one via SessionFactoryBuilder or UUID.randomUUID()\");\nSessionFactoryRegistry.INSTANCE.addSessionFactory(uuid, name, jndiName, instance, jndiService);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the standard Configuration/SessionFactoryBuilder pipeline so the uuid is auto-assigned","In custom bootstrap code, assert options.getUuid() is non-null with a descriptive message","Wrapper factory implementations should reuse the wrapped factory's uuid, not pass null"],"tags":["hibernate","session-factory","registry","uuid","bootstrap","internal-api"],"backgroundTag":"missing-required-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}