Skip to content
Browse files

HHH-7969 more jpa index binding

  • Loading branch information...
1 parent 64358b9 commit 1f3bdf12bdf42caf3344b03af1fb0c7ff7856113 @stliu committed Feb 6, 2013
Showing with 37 additions and 35 deletions.
  1. +37 −35 hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
View
72 hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
@@ -584,16 +584,6 @@ public void finalSecondaryTableBinding(PropertyHolder propertyHolder) {
mappings.addJoins( persistentClass, secondaryTables );
}
- private boolean hasJoinColumns(PrimaryKeyJoinColumn[] pkColumnsAnn,JoinColumn[] joinColumnsAnn){
- if( pkColumnsAnn == null && joinColumnsAnn==null){
- return false;
- }
- int nbrOfJoinColumns = pkColumnsAnn != null ?
- pkColumnsAnn.length :
- joinColumnsAnn.length;
- return nbrOfJoinColumns != 0;
- }
-
private void createPrimaryColumnsToSecondaryTable(Object uncastedColumn, PropertyHolder propertyHolder, Join join) {
Ejb3JoinColumn[] ejb3JoinColumns;
PrimaryKeyJoinColumn[] pkColumnsAnn = null;
@@ -605,7 +595,7 @@ private void createPrimaryColumnsToSecondaryTable(Object uncastedColumn, Propert
joinColumnsAnn = (JoinColumn[]) uncastedColumn;
}
final ForeignKey[] foreignKeys;
- if (hasJoinColumns( pkColumnsAnn, joinColumnsAnn ) ) {
+ if ( pkColumnsAnn == null && joinColumnsAnn == null ) {
ejb3JoinColumns = new Ejb3JoinColumn[1];
ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinColumn(
null,
@@ -620,34 +610,46 @@ private void createPrimaryColumnsToSecondaryTable(Object uncastedColumn, Propert
int nbrOfJoinColumns = pkColumnsAnn != null ?
pkColumnsAnn.length :
joinColumnsAnn.length;
- ejb3JoinColumns = new Ejb3JoinColumn[nbrOfJoinColumns];
- foreignKeys = new ForeignKey[nbrOfJoinColumns];
- if ( pkColumnsAnn != null ) {
- for ( int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++ ) {
- ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
- pkColumnsAnn[colIndex],
- null,
- persistentClass.getIdentifier(),
- secondaryTables,
- propertyHolder, mappings
- );
- foreignKeys[colIndex] = pkColumnsAnn[colIndex].foreignKey();
- }
+ if ( nbrOfJoinColumns == 0 ) {
+ ejb3JoinColumns = new Ejb3JoinColumn[1];
+ ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinColumn(
+ null,
+ null,
+ persistentClass.getIdentifier(),
+ secondaryTables,
+ propertyHolder, mappings
+ );
+ foreignKeys = null;
}
else {
- for ( int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++ ) {
- ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
- null,
- joinColumnsAnn[colIndex],
- persistentClass.getIdentifier(),
- secondaryTables,
- propertyHolder, mappings
- );
- foreignKeys[colIndex] = joinColumnsAnn[colIndex].foreignKey();
+ ejb3JoinColumns = new Ejb3JoinColumn[nbrOfJoinColumns];
+ foreignKeys = new ForeignKey[nbrOfJoinColumns];
+ if ( pkColumnsAnn != null ) {
+ for ( int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++ ) {
+ ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
+ pkColumnsAnn[colIndex],
+ null,
+ persistentClass.getIdentifier(),
+ secondaryTables,
+ propertyHolder, mappings
+ );
+ foreignKeys[colIndex] = pkColumnsAnn[colIndex].foreignKey();
+ }
+ }
+ else {
+ for ( int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++ ) {
+ ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
+ null,
+ joinColumnsAnn[colIndex],
+ persistentClass.getIdentifier(),
+ secondaryTables,
+ propertyHolder, mappings
+ );
+ foreignKeys[colIndex] = joinColumnsAnn[colIndex].foreignKey();
+ }
}
}
}
-
for (Ejb3JoinColumn joinColumn : ejb3JoinColumns) {
joinColumn.forceNotNull();
}
@@ -659,7 +661,7 @@ private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColum
join.setKey( key );
setFKNameIfDefined( join );
key.setCascadeDeleteEnabled( false );
- TableBinder.bindFk( persistentClass, null, ejb3JoinColumns, key, false, mappings );
+ TableBinder.bindFk( persistentClass, null, ejb3JoinColumns,foreignKeys, key, false, mappings );
join.createPrimaryKey();
join.createForeignKey();
persistentClass.addJoin( join );

0 comments on commit 1f3bdf1

Please sign in to comment.
Something went wrong with that request. Please try again.