Use BAG for unowned OneToMany and throw an error if @OrderColumn is found on unowned ManyToMany

This commit is contained in:
Christian Beikov 2022-02-10 16:33:14 +01:00
parent 8183901cfe
commit b6b500200b
2 changed files with 16 additions and 0 deletions

View File

@ -2377,6 +2377,17 @@ public final class AnnotationBinder {
);
}
if ( property.isAnnotationPresent( OrderColumn.class )
&& manyToManyAnn != null && !manyToManyAnn.mappedBy().isEmpty() ) {
throw new AnnotationException(
"Explicit @OrderColumn on inverse side of @ManyToMany is illegal: "
+ BinderHelper.getPath(
propertyHolder,
inferredData
)
);
}
final IndexColumn indexColumn = IndexColumn.fromAnnotations(
property.getAnnotation( OrderColumn.class ),
property.getAnnotation( org.hibernate.annotations.IndexColumn.class ),

View File

@ -565,6 +565,11 @@ public abstract class CollectionBinder {
// We don't support @OrderColumn on the non-owning side of a many-to-many association.
return CollectionClassification.BAG;
}
OneToMany oneToMany = property.getAnnotation( OneToMany.class );
if ( oneToMany != null && ! StringHelper.isEmpty( oneToMany.mappedBy() ) ) {
// Unowned to-many mappings are always considered BAG by default
return CollectionClassification.BAG;
}
// otherwise, return the implicit classification for List attributes
return buildingContext.getBuildingOptions().getMappingDefaults().getImplicitListClassification();
}