hibernate/hibernate-orm · error · AnnotationException

Property '<path>' is the inverse side of a '@OneToOne' assoc

Error message

Property '<path>' is the inverse side of a '@OneToOne' association and cannot be used as identifier

What it means

Error "Property '<path>' is the inverse side of a '@OneToOne' association and cannot be used as identifier" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java:473

			boolean isIdentifierMapper,
			boolean inSecondPass,
			MetadataBuildingContext context,
			AnnotatedJoinColumns joinColumns,
			PropertyBinder propertyBinder) {
		final var memberDetails = inferredData.getAttributeMember();
		final var oneToOne = memberDetails.getDirectAnnotationUsage( OneToOne.class );

		//check validity
		if ( memberDetails.hasDirectAnnotationUsage( Column.class ) ) {
			throw new AnnotationException(
					"Property '" + getPath( propertyHolder, inferredData )
							+ "' is a '@OneToOne' association and may not use '@Column' to specify column mappings"
							+ " (use '@PrimaryKeyJoinColumn' instead)"
			);
		}

		if ( joinColumns.hasMappedBy() && isIdentifier( propertyHolder, propertyBinder, isIdentifierMapper ) ) {
			throw new AnnotationException(
					"Property '" + getPath( propertyHolder, inferredData )
							+ "' is the inverse side of a '@OneToOne' association and cannot be used as identifier"
			);
		}

		//FIXME support a proper PKJCs
		final boolean trueOneToOne = memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class )
				|| memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class );
		bindOneToOne(
				aggregateCascadeTypes( oneToOne.cascade(), memberDetails, oneToOne.orphanRemoval(), context ),
				joinColumns,
				oneToOne.optional(),
				oneToOne.fetch(),
				propertyHolder,
				nullability,
				inferredData,
				nullIfEmpty( oneToOne.mappedBy() ),
				trueOneToOne,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Make the owning side the identifier: put @Id (and @MapsId if deriving the id) on the side that owns the foreign key, and mark the inverse side with mappedBy.
  2. If you only need a plain association, remove @Id from the inverse-side property so it is not used as the identifier.

Example fix

Make the owning side the identifier: put @Id (and @MapsId if deriving the id) on the side that owns the foreign key, and mark the inverse side with mappedBy.

When it happens

Trigger: An entity mapping annotation or bootstrap configuration violates a Hibernate mapping rule.

Common situations: Annotation mapping mistakes: inverse-side @Id associations, @Column on @OneToOne, unmapped association targets, mismatched @EnumeratedValue/@Temporal usage, duplicate sequence generators.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/8a89c7faa5b4421c. Report an issue: GitHub.