@SuppressWarnings("unchecked")
    protected void bindManyToOne(Association property, ManyToOne manyToOne,
                                 String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) {

        NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

        bindManyToOneValues(property, manyToOne);
        PersistentEntity refDomainClass = property instanceof ManyToMany ? property.getOwner() : property.getAssociatedEntity();
        Mapping mapping = getMapping(refDomainClass);
        boolean isComposite = hasCompositeIdentifier(mapping);
        if (isComposite) {
            CompositeIdentity ci = (CompositeIdentity) mapping.getIdentity();
            bindCompositeIdentifierToManyToOne(property, manyToOne, ci, refDomainClass, path, sessionFactoryBeanName);
        }
        else {
            if (property.isCircular() && (property instanceof ManyToMany)) {
                PropertyConfig pc = getPropertyConfig(property);

                if (pc.getColumns().isEmpty()) {
                    mapping.getColumns().put(property.getName(), pc);
                }
                if (!hasJoinKeyMapping(pc) ) {
                    JoinTable jt = new JoinTable();
                    final ColumnConfig columnConfig = new ColumnConfig();
                    columnConfig.setName(namingStrategy.propertyToColumnName(property.getName()) +
                            UNDERSCORE + FOREIGN_KEY_SUFFIX);
                    jt.setKey(columnConfig);
                    pc.setJoinTable(jt);
                }
                bindSimpleValue(property, manyToOne, path, pc, sessionFactoryBeanName);
            }
            else {
                // bind column
                bindSimpleValue(property, null, manyToOne, path, mappings, sessionFactoryBeanName);
            }
        }

        PropertyConfig config = getPropertyConfig(property);
        if ((property instanceof org.grails.datastore.mapping.model.types.OneToOne) && !isComposite) {
            manyToOne.setAlternateUniqueKey(true);
            Column c = getColumnForSimpleValue(manyToOne);
            if (config != null && !config.isUniqueWithinGroup()) {
                c.setUnique(config.isUnique());
            }
            else if (property.isBidirectional() && isHasOne(property.getInverseSide())) {
                c.setUnique(true);
            }
        }
    }
@ SuppressWarnings ( "unchecked" ) protected void bindManyToOne ( Association property , ManyToOne manyToOne , String path , InFlightMetadataCollector mappings , String sessionFactoryBeanName ) { NamingStrategy namingStrategy = getNamingStrategy ( sessionFactoryBeanName ) ; bindManyToOneValues ( property , manyToOne ) ; PersistentEntity refDomainClass = property instanceof ManyToMany ? property . getOwner ( ) : property . getAssociatedEntity ( ) ; Mapping mapping = getMapping ( refDomainClass ) ; boolean isComposite = hasCompositeIdentifier ( mapping ) ; if ( isComposite ) { CompositeIdentity ci = ( CompositeIdentity ) mapping . getIdentity ( ) ; bindCompositeIdentifierToManyToOne ( property , manyToOne , ci , refDomainClass , path , sessionFactoryBeanName ) ; } else { if ( property . isCircular ( ) && ( property instanceof ManyToMany ) ) { PropertyConfig pc = getPropertyConfig ( property ) ; if ( pc . getColumns ( ) . isEmpty ( ) ) { mapping . getColumns ( ) . put ( property . getName ( ) , pc ) ; } if ( ! hasJoinKeyMapping ( pc ) ) { JoinTable jt = new JoinTable ( ) ; final ColumnConfig columnConfig = new ColumnConfig ( ) ; columnConfig . setName ( namingStrategy . propertyToColumnName ( property . getName ( ) ) + UNDERSCORE + FOREIGN_KEY_SUFFIX ) ; jt . setKey ( columnConfig ) ; pc . setJoinTable ( jt ) ; } bindSimpleValue ( property , manyToOne , path , pc , sessionFactoryBeanName ) ; } else { bindSimpleValue ( property , null , manyToOne , path , mappings , sessionFactoryBeanName ) ; } } PropertyConfig config = getPropertyConfig ( property ) ; if ( ( property instanceof org . grails . datastore . mapping . model . types . OneToOne ) && ! isComposite ) { manyToOne . setAlternateUniqueKey ( true ) ; Column c = getColumnForSimpleValue ( manyToOne ) ; if ( config != null && ! config . isUniqueWithinGroup ( ) ) { c . setUnique ( config . isUnique ( ) ) ; } else if ( property . isBidirectional ( ) && isHasOne ( property . getInverseSide ( ) ) ) { c . setUnique ( true ) ; } } }
Binds a many-to-one relationship to the