{"record":{"id":"fa85742a2aa25390","repo":"hibernate/hibernate-orm","slug":"could-not-assign-id-from-null-association","errorCode":null,"errorMessage":"Could not assign id from null association '","messagePattern":"Could not assign id from null association '","errorType":"exception","errorClass":"IdentifierGenerationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java","lineNumber":117,"sourceCode":"\t\tif ( sessionImplementor.isManaged( object ) ) {\n\t\t\t//abort the save (the object is already saved by a circular cascade)\n\t\t\treturn SHORT_CIRCUIT_INDICATOR;\n\t\t\t//throw new IdentifierGenerationException(\"save associated object first, or disable cascade for inverse association\");\n\t\t}\n\t\telse {\n\t\t\tfinal var persister =\n\t\t\t\t\tsessionImplementor.getFactory().getMappingMetamodel()\n\t\t\t\t\t\t\t.getEntityDescriptor( entityName );\n\t\t\treturn identifier( sessionImplementor, entityType( propertyName, persister ),\n\t\t\t\t\tassociatedEntity( entityName, propertyName, object, persister ) );\n\t\t}\n\t}\n\n\tprivate static Object associatedEntity(\n\t\t\tString entityName, String propertyName, Object object, EntityPersister entityDescriptor) {\n\t\tfinal Object associatedObject = entityDescriptor.getPropertyValue( object, propertyName );\n\t\tif ( associatedObject == null ) {\n\t\t\tthrow new IdentifierGenerationException( \"Could not assign id from null association '\" + propertyName\n\t\t\t\t\t+ \"' of entity '\" + entityName + \"'\" );\n\t\t}\n\t\treturn associatedObject;\n\t}\n\n\tprivate static Object identifier(\n\t\t\tSharedSessionContractImplementor session,\n\t\t\tEntityType foreignValueSourceType,\n\t\t\tObject associatedEntity) {\n\t\tfinal String associatedEntityName = foreignValueSourceType.getAssociatedEntityName();\n\t\ttry {\n\t\t\treturn getEntityIdentifierIfNotUnsaved( associatedEntityName, associatedEntity, session );\n\t\t}\n\t\tcatch (TransientObjectException toe) {\n\t\t\tif ( session instanceof Session statefulSession ) {\n\t\t\t\tstatefulSession.persist( associatedEntityName, associatedEntity );\n\t\t\t\treturn session.getContextEntityIdentifier( associatedEntity );\n\t\t\t}","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java#L99-L135","documentation":"Raised while resolving the identifier of an associated entity used as a foreign id: the association object is not managed and not resolvable, so Hibernate cannot derive the owning entity's id from it. Typically the associated instance is transient and cascade is not saving it first.","triggerScenarios":"Thrown when a foreign id generator cannot obtain the id from the associated entity.","commonSituations":"Typical situations: missing 'property' param on the foreign generator; the association is null when the id is generated.","solutions":["Ensure the associated entity referenced for id derivation is set and non-null before persisting.","Persist or load the parent/associated entity first so the foreign id can be derived."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}