Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.PrimaryKeyJoinColumn;

import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath;
import java.util.Locale;

import static org.hibernate.internal.util.StringHelper.isEmpty;
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
import static org.hibernate.internal.util.StringHelper.isQuoted;
Expand Down Expand Up @@ -109,9 +110,13 @@ static AnnotatedJoinColumn buildJoinColumn(
String defaultColumnSuffix) {
if ( joinColumn != null ) {
if ( mappedBy != null ) {
throw new AnnotationException( "Association '"
+ getRelativePath( propertyHolder, inferredData.getPropertyName() )
+ "' is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'" );
throw new AnnotationException(
String.format(
Locale.ROOT,
"Association '%s' of entity '%s' is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'",
inferredData.getPropertyName(),
propertyHolder.getEntityName() )
);
}
return explicitJoinColumn( joinColumn, parent, inferredData, defaultColumnSuffix );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ public void disallowOnSideWithMappedBy() {
.buildMetadata()
);

String errorMessage = ex.getMessage();
assertTrue(
ex.getMessage().contains( "is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'" ),
errorMessage.contains( "is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'" ),
"Should disallow exactly because of @JoinColumn override on side with mappedBy"
);
assertTrue( errorMessage.contains( "Association 'desk'" ),
"The error message doesn't contain the name of the association" );
assertTrue( errorMessage.contains( PartTimeEmployee.class.getSimpleName() ),
"The error message doesn't contain the name of the entity" );

}
}

Expand Down