Search in sources :

Example 1 with ImplicitIdentifierColumnNameSource

use of org.hibernate.boot.model.naming.ImplicitIdentifierColumnNameSource in project hibernate-orm by hibernate.

the class ModelBinder method bindSimpleEntityIdentifier.

private void bindSimpleEntityIdentifier(MappingDocument sourceDocument, final EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
    final IdentifierSourceSimple idSource = (IdentifierSourceSimple) hierarchySource.getIdentifierSource();
    final SimpleValue idValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
    rootEntityDescriptor.setIdentifier(idValue);
    bindSimpleValueType(sourceDocument, idSource.getIdentifierAttributeSource().getTypeInformation(), idValue);
    final String propertyName = idSource.getIdentifierAttributeSource().getName();
    if (propertyName == null || !rootEntityDescriptor.hasPojoRepresentation()) {
        if (!idValue.isTypeSpecified()) {
            throw new MappingException("must specify an identifier type: " + rootEntityDescriptor.getEntityName(), sourceDocument.getOrigin());
        }
    } else {
        idValue.setTypeUsingReflection(rootEntityDescriptor.getClassName(), propertyName);
    }
    relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, ((RelationalValueSourceContainer) idSource.getIdentifierAttributeSource()).getRelationalValueSources(), idValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {

        @Override
        public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
            context.getBuildingOptions().getImplicitNamingStrategy().determineIdentifierColumnName(new ImplicitIdentifierColumnNameSource() {

                @Override
                public EntityNaming getEntityNaming() {
                    return hierarchySource.getRoot().getEntityNamingSource();
                }

                @Override
                public AttributePath getIdentifierAttributePath() {
                    return idSource.getIdentifierAttributeSource().getAttributePath();
                }

                @Override
                public MetadataBuildingContext getBuildingContext() {
                    return context;
                }
            });
            return database.toIdentifier(propertyName);
        }
    });
    if (propertyName != null) {
        Property prop = new Property();
        prop.setValue(idValue);
        bindProperty(sourceDocument, idSource.getIdentifierAttributeSource(), prop);
        rootEntityDescriptor.setIdentifierProperty(prop);
        rootEntityDescriptor.setDeclaredIdentifierProperty(prop);
    }
    makeIdentifier(sourceDocument, idSource.getIdentifierGeneratorDescriptor(), idSource.getUnsavedValue(), idValue);
}
Also used : ImplicitIdentifierColumnNameSource(org.hibernate.boot.model.naming.ImplicitIdentifierColumnNameSource) Identifier(org.hibernate.boot.model.naming.Identifier) IdentifierSourceSimple(org.hibernate.boot.model.source.spi.IdentifierSourceSimple) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty) SimpleValue(org.hibernate.mapping.SimpleValue) MappingException(org.hibernate.boot.MappingException)

Aggregations

MappingException (org.hibernate.boot.MappingException)1 Identifier (org.hibernate.boot.model.naming.Identifier)1 ImplicitIdentifierColumnNameSource (org.hibernate.boot.model.naming.ImplicitIdentifierColumnNameSource)1 IdentifierSourceSimple (org.hibernate.boot.model.source.spi.IdentifierSourceSimple)1 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)1 Property (org.hibernate.mapping.Property)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)1