// DISCRIMINATOR
final Object discriminatorValue;
if ( persistentClass.isPolymorphic() ) {
Value discrimValue = persistentClass.getDiscriminator();
if (discrimValue==null) {
throw new MappingException("discriminator mapping required for single table polymorphic persistence");
}
forceDiscriminator = persistentClass.isForceDiscriminator();
Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
if ( discrimValue.hasFormula() ) {
Formula formula = (Formula) selectable;
discriminatorFormula = formula.getFormula();
discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
discriminatorColumnName = null;
discriminatorAlias = "clazz_";
}
else {
Column column = (Column) selectable;
discriminatorColumnName = column.getQuotedName( factory.getDialect() );
discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
discriminatorFormula = null;
discriminatorFormulaTemplate = null;
}
discriminatorType = persistentClass.getDiscriminator().getType();
if ( persistentClass.isDiscriminatorValueNull() ) {
discriminatorValue = NULL_DISCRIMINATOR;
discriminatorSQLValue = InFragment.NULL;
discriminatorInsertable = false;
}
else if ( persistentClass.isDiscriminatorValueNotNull() ) {
discriminatorValue = NOT_NULL_DISCRIMINATOR;
discriminatorSQLValue = InFragment.NOT_NULL;
discriminatorInsertable = false;
}
else {
discriminatorInsertable = persistentClass.isDiscriminatorInsertable() && !discrimValue.hasFormula();
try {
DiscriminatorType dtype = (DiscriminatorType) discriminatorType;
discriminatorValue = dtype.stringToObject( persistentClass.getDiscriminatorValue() );
discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() );
}