{"record":{"id":"5e664709e2bed170","repo":"hibernate/hibernate-orm","slug":"id-generator-object-or-name-is-null","errorCode":null,"errorMessage":"Id generator object or name is null","messagePattern":"Id generator object or name is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java","lineNumber":643,"sourceCode":"\t\tif ( name == null ) {\n\t\t\tthrow new IllegalArgumentException( \"null is not a valid generator name\" );\n\t\t}\n\t\treturn idGeneratorDefinitionMap.get( name );\n\t}\n\n\t@Override\n\tpublic java.util.Collection<Table> collectTableMappings() {\n\t\tfinal ArrayList<Table> tables = new ArrayList<>();\n\t\tfor ( Namespace namespace : getDatabase().getNamespaces() ) {\n\t\t\ttables.addAll( namespace.getTables() );\n\t\t}\n\t\treturn tables;\n\t}\n\n\t@Override\n\tpublic void addIdentifierGenerator(IdentifierGeneratorDefinition generator) {\n\t\tif ( generator == null || generator.getName() == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Id generator object or name is null\" );\n\t\t}\n\t\telse if ( !generator.getName().isEmpty()\n\t\t\t\t\t&& !defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {\n\t\t\tfinal var old = idGeneratorDefinitionMap.put( generator.getName(), generator );\n\t\t\tif ( old != null && !old.equals( generator ) ) {\n\t\t\t\tif ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {\n\t\t\t\t\tthrow new IllegalArgumentException( \"Duplicate generator name '\" + old.getName()\n\t\t\t\t\t\t\t+ \"'; you will likely want to set the property '\"\n\t\t\t\t\t\t\t+ JpaComplianceSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE\n\t\t\t\t\t\t\t+ \"' to false \" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tBOOT_LOGGER.duplicateGeneratorName( old.getName() );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java#L625-L661","documentation":"addIdentifierGenerator is the registration point for named id generators (sequence/table style definitions). It throws IllegalArgumentException 'Id generator object or name is null' when called with a null IdentifierGeneratorDefinition or one whose name is null, before any map interaction happens.","triggerScenarios":"Programmatically adding an IdentifierGeneratorDefinition that was built without a name (e.g. new IdentifierGeneratorDefinition(null, strategy, params)), or a null definition forwarded by an integration; the guard is at InFlightMetadataCollectorImpl.java:645-647.","commonSituations":"Custom bootstrap code copying generator definitions between metadata instances; integrations constructing definitions from partial configuration; refactoring that dropped the name argument.","solutions":["Always construct the definition with a name: new IdentifierGeneratorDefinition(\"user_seq\", strategy, params)","Null-check the generator and its name before calling addIdentifierGenerator","Skip registration entirely for null definitions rather than forwarding them"],"exampleFix":"// before: definition without a name\nIdentifierGeneratorDefinition def =\n        new IdentifierGeneratorDefinition(null, \"sequence\", params);\n\n// after\nIdentifierGeneratorDefinition def =\n        new IdentifierGeneratorDefinition(\"user_seq\", \"sequence\", params);\ncollector.addIdentifierGenerator(def);","handlingStrategy":"validation","validationCode":"if (generator == null || generator.getName() == null) {\n    throw new IllegalArgumentException(\"id generator requires a name: \" + generator);\n}\ncollector.addIdentifierGenerator(generator);","typeGuard":"static boolean isRegistrableGenerator(IdentifierGeneratorDefinition g) {\n    return g != null && g.getName() != null;\n}","tryCatchPattern":null,"preventionTips":["Always pass a name when constructing IdentifierGeneratorDefinition","Skip null definitions at the source instead of forwarding them to the collector"],"tags":["hibernate","id-generator","metadata","null-check"],"backgroundTag":"invalid-generator-definition","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}