Skip to content

Commit

Permalink
HHH-10385 HHH-10386 - Fix the @joincolumn foreignKey is not taken int…
Browse files Browse the repository at this point in the history
…o consideration when generating the association database schema
  • Loading branch information
dreab8 committed Jan 12, 2016
1 parent 90c1de5 commit eae981c
Showing 1 changed file with 25 additions and 4 deletions.
Expand Up @@ -1110,12 +1110,22 @@ private static SimpleValue buildCollectionKey(
else {
final JoinTable joinTableAnn = property.getAnnotation( JoinTable.class );
if ( joinTableAnn != null ) {
if ( joinTableAnn.foreignKey().value() == ConstraintMode.NO_CONSTRAINT ) {
String foreignKeyName = joinTableAnn.foreignKey().name();
ConstraintMode foreignKeyValue = joinTableAnn.foreignKey().value();
if ( joinTableAnn.joinColumns().length != 0 ) {
final JoinColumn joinColumnAnn = joinTableAnn.joinColumns()[0];
if ( "".equals( foreignKeyName ) ) {
foreignKeyName = joinColumnAnn.foreignKey().name();
}
if ( foreignKeyValue != ConstraintMode.NO_CONSTRAINT ) {
foreignKeyValue = joinColumnAnn.foreignKey().value();
}
}
if ( foreignKeyValue == ConstraintMode.NO_CONSTRAINT ) {
key.setForeignKeyName( "none" );
}
else {
key.setForeignKeyName( StringHelper.nullIfEmpty( joinTableAnn.foreignKey().name() ) );

key.setForeignKeyName( StringHelper.nullIfEmpty( foreignKeyName ) );
}
}
else {
Expand Down Expand Up @@ -1304,11 +1314,22 @@ else if ( anyAnn != null ) {
else {
final JoinTable joinTableAnn = property.getAnnotation( JoinTable.class );
if ( joinTableAnn != null ) {
String foreignKeyName = joinTableAnn.inverseForeignKey().name();
ConstraintMode foreignKeyValue = joinTableAnn.foreignKey().value();
if ( joinTableAnn.inverseJoinColumns().length != 0 ) {
final JoinColumn joinColumnAnn = joinTableAnn.inverseJoinColumns()[0];
if ( "".equals( foreignKeyName ) ) {
foreignKeyName = joinColumnAnn.foreignKey().name();
}
if ( foreignKeyValue != ConstraintMode.NO_CONSTRAINT ) {
foreignKeyValue = joinColumnAnn.foreignKey().value();
}
}
if ( joinTableAnn.foreignKey().value() == ConstraintMode.NO_CONSTRAINT ) {
element.setForeignKeyName( "none" );
}
else {
element.setForeignKeyName( StringHelper.nullIfEmpty( joinTableAnn.inverseForeignKey().name() ) );
element.setForeignKeyName( StringHelper.nullIfEmpty( foreignKeyName ) );
}
}
}
Expand Down

0 comments on commit eae981c

Please sign in to comment.