Skip to content

Commit

Permalink
OGM-1198 Make sure to return the right AssociationKeyMetadata
Browse files Browse the repository at this point in the history
  This fix make sure that when looking for the AssociationKeyMetadata, we consider
  the mappedBy value on the non-owning side of the association.

  Failing to do that causes some errors when there are multiple associations to the same entity
  • Loading branch information
DavideD authored and gsmet committed Nov 2, 2016
1 parent 2682412 commit dcee58a
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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 @@ -76,8 +77,11 @@ public static AssociationKeyMetadata getInverseAssociationKeyMetadata(OgmEntityP
// candidate is a *-to-many association
if ( type.isCollectionType() ) {
OgmCollectionPersister inverseCollectionPersister = getPersister( factory, (CollectionType) type );
if ( isCollectionMatching( mainSideJoinable, inverseCollectionPersister ) ) {
return inverseCollectionPersister.getAssociationKeyMetadata();
String mappedByProperty = inverseCollectionPersister.getMappedByProperty();
if ( StringHelper.isEmpty( mappedByProperty ) || mainSideProperty.equals( mappedByProperty ) ) {
if ( isCollectionMatching( mainSideJoinable, inverseCollectionPersister ) ) {
return inverseCollectionPersister.getAssociationKeyMetadata();
}
}
}
}
Expand Down

0 comments on commit dcee58a

Please sign in to comment.