{"record":{"id":"4404d373ed819e58","repo":"hibernate/hibernate-orm","slug":"to-one-attribute-s-s-cannot-be-mapped-as-lazy","errorCode":null,"errorMessage":"To-one attribute (%s.%s) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete","messagePattern":"To-one attribute \\((.+?)\\.(.+?)\\) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete","errorType":"exception","errorClass":"UnsupportedMappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java","lineNumber":460,"sourceCode":"\t\t\t\tthe navigable path is NavigablePath(Card.fields.{element}.{id}.card) and it does not contain the \"primaryKey\" part,\n\t\t\t\tso in order to recognize the bidirectionality the \"primaryKey.\" is removed from the otherSidePropertyName value.\n\t\t\t */\n\t\t\tfinal var oneToOne = (OneToOne) bootValue;\n\t\t\tfinal String mappedByProperty = oneToOne.getMappedByProperty();\n\t\t\tbidirectionalAttributePath =\n\t\t\t\t\tmappedByProperty == null\n\t\t\t\t\t\t\t? SelectablePath.parse( referencedPropertyName )\n\t\t\t\t\t\t\t: SelectablePath.parse( mappedByProperty );\n\t\t\tnotFoundAction = null;\n\t\t\tisKeyTableNullable = isNullable();\n\t\t\tisOptional = !bootValue.isConstrained();\n\t\t\tisInternalLoadNullable = isNullable();\n\t\t}\n\n\t\tif ( entityMappingType.getSoftDeleteMapping() != null\n\t\t\t\t// cannot be lazy\n\t\t\t\t&& getTiming() == FetchTiming.DELAYED ) {\n\t\t\tthrow new UnsupportedMappingException( String.format(\n\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\"To-one attribute (%s.%s) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete\",\n\t\t\t\t\tdeclaringType.getPartName(),\n\t\t\t\t\tgetAttributeName()\n\t\t\t) );\n\t\t}\n\n\t\tif ( referencedPropertyName == null ) {\n\t\t\tfinal Set<String> targetKeyPropertyNames = new HashSet<>( 2 );\n\t\t\ttargetKeyPropertyNames.add( EntityIdentifierMapping.ID_ROLE_NAME );\n\t\t\tfinal var entityBinding =\n\t\t\t\t\tbootValue.getBuildingContext().getMetadataCollector()\n\t\t\t\t\t\t\t.getEntityBinding( entityMappingType.getEntityName() );\n\t\t\tfinal var identifierMapper = entityBinding.getIdentifierMapper();\n\t\t\tfinal var propertyType =\n\t\t\t\t\tidentifierMapper == null\n\t\t\t\t\t\t\t? entityBinding.getIdentifier().getType()\n\t\t\t\t\t\t\t: identifierMapper.getType();","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java#L442-L478","documentation":"Error \"To-one attribute (%s.%s) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a to-one association is mapped LAZY but its target entity is annotated @SoftDelete, which requires eager availability.","commonSituations":"See trigger scenarios.","solutions":["Use FetchType.EAGER for the association to the @SoftDelete entity.","Remove @SoftDelete from the target entity if lazy loading of the association is required."],"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"}