if ( collectionMetadataKey == null ) {
final Object[] columnValues = getKeyColumnValues();
collectionMetadataKey = new AssociationKey( tableName, keyColumnNames, columnValues );
// We have a collection on the main side
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
);
collectionMetadataKey.setCollectionRole( buildCollectionRole(collectionPersister) );
}
else {
//we are on the right side, use the association property
collectionMetadataKey.setCollectionRole( getUnqualifiedRole( collectionPersister ) );
entityKey = EntityKeyBuilder.fromPersister(
(OgmEntityPersister) collectionPersister.getOwnerEntityPersister(),
(Serializable) key,
session
);
}
collectionMetadataKey.setOwnerEntityKey( entityKey );
//TODO add information on the collection type, set, map, bag, list etc
AssociationKind type = collectionPersister.getElementType().isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED;
collectionMetadataKey.setAssociationKind( type );
collectionMetadataKey.setRowKeyColumnNames( collectionPersister.getRowKeyColumnNames() );
}
// We have a to-one on the main side
else if ( propertyType != null ) {
collectionMetadataKey.setAssociationKind( propertyType.isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED );
if ( propertyType instanceof EntityType ) {
EntityType entityType = (EntityType) propertyType;
OgmEntityPersister associatedPersister = (OgmEntityPersister) entityType.getAssociatedJoinable( session.getFactory() );
EntityKey entityKey = new EntityKey(
associatedPersister.getTableName(),
associatedPersister.getIdentifierColumnNames(),
columnValues
);
collectionMetadataKey.setOwnerEntityKey( entityKey );