if (collectionPersister != null) {
EntityKey entityKey;
// we are explicitly looking to update the non owning side
if ( inverse ) {
//look for the other side of the collection, build the key of the other side's entity
OgmEntityPersister elementPersister = (OgmEntityPersister) collectionPersister.getElementPersister();
entityKey = EntityKeyBuilder.fromPersister(
elementPersister,
(Serializable) key,
session
);
collectionRole = buildCollectionRole( collectionPersister );
}
else {
//we are on the right side, use the association property
collectionRole = getUnqualifiedRole( collectionPersister );
entityKey = EntityKeyBuilder.fromPersister(
(OgmEntityPersister) collectionPersister.getOwnerEntityPersister(),
(Serializable) key,
session
);
}
ownerEntityKey = entityKey;
//TODO add information on the collection type, set, map, bag, list etc
AssociationKind type = collectionPersister.getElementType().isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED_COLLECTION;
associationKind = type;
}
// We have a to-one on the main side
else if ( propertyType != null ) {
associationKind = propertyType.isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED_COLLECTION;
if ( propertyType instanceof EntityType ) {
EntityType entityType = (EntityType) propertyType;
OgmEntityPersister associatedPersister = (OgmEntityPersister) entityType.getAssociatedJoinable( session.getFactory() );
EntityKey entityKey = new EntityKey(
associatedPersister.getEntityKeyMetadata(),
columnValues
);
ownerEntityKey = entityKey;
collectionRole = getCollectionRoleFromToOne( associatedPersister );
}