public OgmCollectionPersister()

in core/src/main/java/org/hibernate/ogm/persister/impl/OgmCollectionPersister.java [113:165]


	public OgmCollectionPersister(final Collection collection, final CollectionDataAccess cacheDataAccess, PersisterCreationContext persisterCreationContext)
			throws MappingException, CacheException {
		super( collection, cacheDataAccess, persisterCreationContext );

		SessionFactoryImplementor factory = persisterCreationContext.getSessionFactory();
		ServiceRegistry registry = factory.getServiceRegistry();
		final TypeTranslator typeTranslator = registry.getService( TypeTranslator.class );
		this.gridDialect = registry.getService( GridDialect.class );

		keyGridType = typeTranslator.getType( getKeyType() );
		elementGridType = typeTranslator.getType( getElementType() );
		indexGridType = typeTranslator.getType( getIndexType() );
		identifierGridType = typeTranslator.getType( getIdentifierType() );
		// copied from the superclass constructor
		isInverse = collection.isInverse();
		oneToMany = collection.isOneToMany();
		if ( collection.isOneToMany() && getElementPersister() != null && getElementType().isEntityType() ) {
			associationType = AssociationType.EMBEDDED_FK_TO_ENTITY;
			final Type identifierOrUniqueKeyType = ( (EntityType) getElementType() )
					.getIdentifierOrUniqueKeyType( factory );
			gridTypeOfAssociatedId = typeTranslator.getType( identifierOrUniqueKeyType );
		}
		else if ( collection.isOneToMany() ) {
			// one to many but not what we expected
			throw new AssertionFailure( "Association marked as one to many but has no ManyToOneType: " + collection.getRole() );
		}
		else if ( getElementType().isAssociationType() && getElementType().isEntityType() ) {
			associationType = AssociationType.ASSOCIATION_TABLE_TO_ENTITY;
			final Type identifierOrUniqueKeyType = ( (EntityType) getElementType() ).getIdentifierOrUniqueKeyType( factory );
			gridTypeOfAssociatedId = typeTranslator.getType( identifierOrUniqueKeyType );
		}
		else {
			gridTypeOfAssociatedId = null;
			associationType = AssociationType.OTHER;
		}

		RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
		String[] rowKeyColumnNames = rowKeyBuilder.getColumnNames();
		String[] rowKeyIndexColumnNames = rowKeyBuilder.getIndexColumnNames();

		associationKeyMetadata = new DefaultAssociationKeyMetadata.Builder()
				.table( getTableName() )
				.columnNames( getKeyColumnNames() )
				.rowKeyColumnNames( rowKeyColumnNames )
				.rowKeyIndexColumnNames( rowKeyIndexColumnNames )
				.entityKeyMetadata( ( (OgmEntityPersister) getOwnerEntityPersister() ).getEntityKeyMetadata() )
				.associatedEntityKeyMetadata( new DefaultAssociatedEntityKeyMetadata( getElementColumnNames(), targetEntityKeyMetadata( false ) ) )
				.inverse( isInverse )
				.collectionRole( getUnqualifiedRole() )
				.associationKind( getElementType().isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED_COLLECTION )
				.associationType( getAssociationType( collection ) )
				.build();
	}