hibernate/hibernate-orm · error · UnsupportedMappingException
To-one attribute (%s.%s) cannot be mapped as LAZY as its ass
Error message
To-one attribute (%s.%s) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete
What it means
Error "To-one attribute (%s.%s) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java:460
the navigable path is NavigablePath(Card.fields.{element}.{id}.card) and it does not contain the "primaryKey" part,
so in order to recognize the bidirectionality the "primaryKey." is removed from the otherSidePropertyName value.
*/
final var oneToOne = (OneToOne) bootValue;
final String mappedByProperty = oneToOne.getMappedByProperty();
bidirectionalAttributePath =
mappedByProperty == null
? SelectablePath.parse( referencedPropertyName )
: SelectablePath.parse( mappedByProperty );
notFoundAction = null;
isKeyTableNullable = isNullable();
isOptional = !bootValue.isConstrained();
isInternalLoadNullable = isNullable();
}
if ( entityMappingType.getSoftDeleteMapping() != null
// cannot be lazy
&& getTiming() == FetchTiming.DELAYED ) {
throw new UnsupportedMappingException( String.format(
Locale.ROOT,
"To-one attribute (%s.%s) cannot be mapped as LAZY as its associated entity is defined with @SoftDelete",
declaringType.getPartName(),
getAttributeName()
) );
}
if ( referencedPropertyName == null ) {
final Set<String> targetKeyPropertyNames = new HashSet<>( 2 );
targetKeyPropertyNames.add( EntityIdentifierMapping.ID_ROLE_NAME );
final var entityBinding =
bootValue.getBuildingContext().getMetadataCollector()
.getEntityBinding( entityMappingType.getEntityName() );
final var identifierMapper = entityBinding.getIdentifierMapper();
final var propertyType =
identifierMapper == null
? entityBinding.getIdentifier().getType()
: identifierMapper.getType();View on GitHub (pinned to fad1729dce)
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.
When it happens
Trigger: Thrown when a to-one association is mapped LAZY but its target entity is annotated @SoftDelete, which requires eager availability.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/4404d373ed819e58.
Report an issue: GitHub.