{"record":{"id":"8f4fa132987a684e","repo":"hibernate/hibernate-orm","slug":"entity-has-a-naturalid-property-which-is-a","errorCode":null,"errorMessage":"Entity '{}' has a '@NaturalId' property which is also defined as insert-generated","messagePattern":"Entity '(.+?)' has a '@NaturalId' property which is also defined as insert-generated","errorType":"exception","errorClass":"IdentifierGenerationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/NaturalIdHelper.java","lineNumber":28,"sourceCode":"import org.hibernate.metamodel.mapping.EntityMappingType;\nimport org.hibernate.persister.entity.EntityPersister;\n\nimport static org.hibernate.engine.internal.NaturalIdLogging.NATURAL_ID_LOGGER;\nimport static org.hibernate.pretty.MessageHelper.infoString;\n\n/**\n * @author Gavin King\n */\npublic class NaturalIdHelper {\n\n\tpublic static String[] getNaturalIdPropertyNames(EntityPersister persister) {\n\t\tfinal int[] naturalIdPropertyIndices = persister.getNaturalIdentifierProperties();\n\t\tif ( naturalIdPropertyIndices == null ) {\n\t\t\tthrow new IdentifierGenerationException( \"Entity '\" + persister.getEntityName()\n\t\t\t\t\t+ \"' has no '@NaturalId' property\" );\n\t\t}\n\t\tif ( persister.isNaturalIdentifierInsertGenerated() ) {\n\t\t\tthrow new IdentifierGenerationException( \"Entity '\" + persister.getEntityName()\n\t\t\t\t\t+ \"' has a '@NaturalId' property which is also defined as insert-generated\" );\n\t\t}\n\t\tfinal String[] allPropertyNames = persister.getPropertyNames();\n\t\tfinal String[] propertyNames = new String[naturalIdPropertyIndices.length];\n\t\tfor ( int i = 0; i < naturalIdPropertyIndices.length; i++ ) {\n\t\t\tpropertyNames[i] = allPropertyNames[naturalIdPropertyIndices[i]];\n\t\t}\n\t\treturn propertyNames;\n\t}\n\n\tpublic static void performAnyNeededCrossReferenceSynchronizations(\n\t\t\tboolean synchronizationEnabled,\n\t\t\tEntityMappingType entityMappingType,\n\t\t\tSharedSessionContractImplementor session) {\n\t\t// first check if synchronization (this process) was disabled\n\t\tif ( synchronizationEnabled\n\t\t\t\t// only mutable natural-ids need this processing\n\t\t\t\t&& entityMappingType.requireNaturalIdMapping().isMutable()","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/NaturalIdHelper.java#L10-L46","documentation":"Error \"Entity '{}' has a '@NaturalId' property which is also defined as insert-generated\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a natural-id operation is requested on an entity without a valid @NaturalId mapping.","commonSituations":"Typical situations: calling byNaturalId() for an entity lacking @NaturalId; a natural id also mapped as insert-generated.","solutions":["Remove @Generated(insert-generated) from the @NaturalId property, or use a different property as the natural id."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}