private AssociationKey getAssociationKey() {
if ( associationKey == null ) {
final Object[] columnValues = getKeyColumnValues();
String collectionRole = null;
EntityKey ownerEntityKey = null;
AssociationKind associationKind = null;
// 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
);
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;