private static GenerationStrategyPair buildGenerationStrategyPair(
      final SessionFactoryImplementor sessionFactory, final Property mappingProperty) {
    final ValueGeneration valueGeneration = mappingProperty.getValueGenerationStrategy();
    if (valueGeneration != null
        && valueGeneration.getGenerationTiming() != GenerationTiming.NEVER) {
      // the property is generated in full. build the generation strategy pair.
      if (valueGeneration.getValueGenerator() != null) {
        // in-memory generation
        return new GenerationStrategyPair(
            FullInMemoryValueGenerationStrategy.create(valueGeneration));
      } else {
        // in-db generation
        return new GenerationStrategyPair(create(sessionFactory, mappingProperty, valueGeneration));
      }
    } else if (mappingProperty.getValue() instanceof Component) {
      final CompositeGenerationStrategyPairBuilder builder =
          new CompositeGenerationStrategyPairBuilder(mappingProperty);
      interpretPartialCompositeValueGeneration(
          sessionFactory, (Component) mappingProperty.getValue(), builder);
      return builder.buildPair();
    }

    return NO_GEN_PAIR;
  }
  public static InDatabaseValueGenerationStrategyImpl create(
      SessionFactoryImplementor sessionFactoryImplementor,
      Property mappingProperty,
      ValueGeneration valueGeneration) {
    final int numberOfMappedColumns =
        mappingProperty.getType().getColumnSpan(sessionFactoryImplementor);
    if (numberOfMappedColumns == 1) {
      return new InDatabaseValueGenerationStrategyImpl(
          valueGeneration.getGenerationTiming(),
          valueGeneration.referenceColumnInSql(),
          new String[] {valueGeneration.getDatabaseGeneratedReferencedColumnValue()});

    } else {
      if (valueGeneration.getDatabaseGeneratedReferencedColumnValue() != null) {
        LOG.debugf(
            "Value generator specified column value in reference to multi-column attribute [%s -> %s]; ignoring",
            mappingProperty.getPersistentClass(), mappingProperty.getName());
      }
      return new InDatabaseValueGenerationStrategyImpl(
          valueGeneration.getGenerationTiming(),
          valueGeneration.referenceColumnInSql(),
          new String[numberOfMappedColumns]);
    }
  }
 /**
  * Whether the given value generation strategy requires to read the value from the database or
  * not.
  */
 private boolean isReadRequired(ValueGeneration valueGeneration, GenerationTiming matchTiming) {
   return valueGeneration != null
       && valueGeneration.getValueGenerator() == null
       && timingsMatch(valueGeneration.getGenerationTiming(), matchTiming);
 }
 public static FullInMemoryValueGenerationStrategy create(ValueGeneration valueGeneration) {
   return new FullInMemoryValueGenerationStrategy(
       valueGeneration.getGenerationTiming(), valueGeneration.getValueGenerator());
 }