Skip to content

Commit

Permalink
OGM-1198 Returns null when asking for metadata from the inverse side
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Nov 1, 2016
1 parent d6ed320 commit 3fd1d66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Expand Up @@ -11,7 +11,6 @@
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.ogm.model.key.spi.AssociationKeyMetadata;
import org.hibernate.ogm.util.impl.StringHelper;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Joinable;
import org.hibernate.persister.entity.Loadable;
Expand Down Expand Up @@ -78,7 +77,7 @@ public static AssociationKeyMetadata getInverseAssociationKeyMetadata(OgmEntityP
if ( type.isCollectionType() ) {
OgmCollectionPersister inverseCollectionPersister = getPersister( factory, (CollectionType) type );
String mappedByProperty = inverseCollectionPersister.getMappedByProperty();
if ( StringHelper.isEmpty( mappedByProperty ) || mainSideProperty.equals( mappedByProperty ) ) {
if ( mainSideProperty.equals( mappedByProperty ) ) {
if ( isCollectionMatching( mainSideJoinable, inverseCollectionPersister ) ) {
return inverseCollectionPersister.getAssociationKeyMetadata();
}
Expand Down
Expand Up @@ -63,13 +63,10 @@ public void canObtainInverseMetadataForBiDirectionalManyToMany() {
assertThat( inverseAssociationKeyMetadata.getColumnNames() ).isEqualTo( new String[]{ "bankAccounts_id" } );
assertThat( inverseAssociationKeyMetadata.getRowKeyColumnNames() ).isEqualTo( new String[]{ "bankAccounts_id", "owners_id" } );

// obtain main side collection from the inverse side
// return null from the inverse side
entityPersister = getEntityPersister( BankAccount.class.getName() );
AssociationKeyMetadata mainSideAssociationKeyMetadata = BiDirectionalAssociationHelper.getInverseAssociationKeyMetadata( entityPersister, entityPersister.getPropertyIndex( "owners" ) );
assertThat( mainSideAssociationKeyMetadata ).isNotNull();
assertThat( mainSideAssociationKeyMetadata.getTable() ).isEqualTo( "AccountOwner_BankAccount" );
assertThat( mainSideAssociationKeyMetadata.getColumnNames() ).isEqualTo( new String[]{ "owners_id" } );
assertThat( mainSideAssociationKeyMetadata.getRowKeyColumnNames() ).isEqualTo( new String[]{ "owners_id", "bankAccounts_id" } );
assertThat( mainSideAssociationKeyMetadata ).isNull();
}

@Test
Expand Down

0 comments on commit 3fd1d66

Please sign in to comment.