Skip to content

Commit 9facfbf

Browse files
committed
HHH-18840 validate collection mapping annotations
1 parent 192058f commit 9facfbf

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,23 +1292,48 @@ private void bindExplicitTypes() {
12921292
}
12931293

12941294
private void detectMappedByProblem(boolean isMappedBy) {
1295-
if ( isMappedBy
1296-
&& ( property.hasDirectAnnotationUsage( JoinColumn.class )
1297-
|| property.hasDirectAnnotationUsage( JoinColumns.class ) ) ) {
1298-
throw new AnnotationException( "Association '"
1299-
+ qualify( propertyHolder.getPath(), propertyName )
1300-
+ "' is 'mappedBy' another entity and may not specify the '@JoinColumn'" );
1301-
}
1302-
1303-
if ( isMappedBy
1304-
&& propertyHolder.getJoinTable( property ) != null ) {
1305-
throw new AnnotationException( "Association '"
1306-
+ qualify( propertyHolder.getPath(), propertyName )
1307-
+ "' is 'mappedBy' another entity and may not specify the '@JoinTable'" );
1295+
if ( isMappedBy ) {
1296+
if ( property.hasDirectAnnotationUsage( JoinColumn.class )
1297+
|| property.hasDirectAnnotationUsage( JoinColumns.class ) ) {
1298+
throw new AnnotationException( "Association '"
1299+
+ qualify( propertyHolder.getPath(), propertyName )
1300+
+ "' is 'mappedBy' another entity and may not specify the '@JoinColumn'" );
1301+
}
1302+
if ( propertyHolder.getJoinTable( property ) != null ) {
1303+
throw new AnnotationException( "Association '"
1304+
+ qualify( propertyHolder.getPath(), propertyName )
1305+
+ "' is 'mappedBy' another entity and may not specify the '@JoinTable'" );
1306+
}
1307+
if ( oneToMany ) {
1308+
if ( property.hasDirectAnnotationUsage( MapKeyColumn.class ) ) {
1309+
LOG.warn( "Association '"
1310+
+ qualify( propertyHolder.getPath(), propertyName )
1311+
+ "' is 'mappedBy' another entity and should not specify a '@MapKeyColumn'"
1312+
+ " (use '@MapKey' instead)" );
1313+
}
1314+
if ( property.hasDirectAnnotationUsage( OrderColumn.class ) ) {
1315+
LOG.warn( "Association '"
1316+
+ qualify( propertyHolder.getPath(), propertyName )
1317+
+ "' is 'mappedBy' another entity and should not specify an '@OrderColumn'"
1318+
+ " (use '@OrderBy' instead)" );
1319+
}
1320+
}
1321+
else {
1322+
if ( property.hasDirectAnnotationUsage( MapKeyColumn.class ) ) {
1323+
throw new AnnotationException( "Association '"
1324+
+ qualify( propertyHolder.getPath(), propertyName )
1325+
+ "' is 'mappedBy' another entity and may not specify a '@MapKeyColumn'"
1326+
+ " (use '@MapKey' instead)" );
1327+
}
1328+
if ( property.hasDirectAnnotationUsage( OrderColumn.class ) ) {
1329+
throw new AnnotationException( "Association '"
1330+
+ qualify( propertyHolder.getPath(), propertyName )
1331+
+ "' is 'mappedBy' another entity and may not specify an '@OrderColumn'"
1332+
+ " (use '@OrderBy' instead)" );
1333+
}
1334+
}
13081335
}
1309-
1310-
if ( !isMappedBy
1311-
&& oneToMany
1336+
else if ( oneToMany
13121337
&& property.hasDirectAnnotationUsage( OnDelete.class )
13131338
&& !property.hasDirectAnnotationUsage( JoinColumn.class )
13141339
&& !property.hasDirectAnnotationUsage( JoinColumns.class )) {

0 commit comments

Comments
 (0)