Skip to content

Commit ceb4d06

Browse files
dreab8beikov
authored andcommitted
HHH-17965 @ElementCollection with @CollectionTable throws o.h.MappingException Foreign key must have same number of columns as the referenced primary key
1 parent f46f0c4 commit ceb4d06

File tree

1 file changed

+18
-18
lines changed
  • hibernate-core/src/main/java/org/hibernate/mapping

1 file changed

+18
-18
lines changed

Diff for: hibernate-core/src/main/java/org/hibernate/mapping/Set.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,27 @@ void createPrimaryKey() {
8484
PrimaryKey pk = collectionTable.getPrimaryKey();
8585
if ( pk == null ) {
8686
pk = new PrimaryKey( getCollectionTable() );
87-
}
88-
pk.addColumns( getKey() );
89-
for ( Selectable selectable : getElement().getSelectables() ) {
90-
if ( selectable instanceof Column ) {
91-
Column col = (Column) selectable;
92-
if ( !col.isNullable() ) {
93-
pk.addColumn( col );
94-
}
95-
else {
96-
return;
87+
pk.addColumns( getKey() );
88+
for ( Selectable selectable : getElement().getSelectables() ) {
89+
if ( selectable instanceof Column ) {
90+
Column col = (Column) selectable;
91+
if ( !col.isNullable() ) {
92+
pk.addColumn( col );
93+
}
94+
else {
95+
return;
96+
}
9797
}
9898
}
99+
if ( pk.getColumnSpan() != getKey().getColumnSpan() ) {
100+
collectionTable.setPrimaryKey( pk );
101+
}
102+
// else {
103+
//for backward compatibility, allow a set with no not-null
104+
//element columns, using all columns in the row locator SQL
105+
//TODO: create an implicit not null constraint on all cols?
106+
// }
99107
}
100-
if ( pk.getColumnSpan() != getKey().getColumnSpan() ) {
101-
collectionTable.setPrimaryKey( pk );
102-
}
103-
// else {
104-
//for backward compatibility, allow a set with no not-null
105-
//element columns, using all columns in the row locator SQL
106-
//TODO: create an implicit not null constraint on all cols?
107-
// }
108108
}
109109
// else {
110110
//create an index on the key columns??

0 commit comments

Comments
 (0)