Search in sources :

Example 1 with VersionAttributeSource

use of org.hibernate.boot.model.source.spi.VersionAttributeSource in project hibernate-orm by hibernate.

the class ModelBinder method bindEntityVersion.

private void bindEntityVersion(MappingDocument sourceDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
    final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource();
    final SimpleValue versionValue = new SimpleValue(sourceDocument, rootEntityDescriptor.getTable());
    versionValue.makeVersion();
    bindSimpleValueType(sourceDocument, versionAttributeSource.getTypeInformation(), versionValue);
    relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, versionAttributeSource.getRelationalValueSources(), versionValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {

        @Override
        public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
            return implicitNamingStrategy.determineBasicColumnName(versionAttributeSource);
        }
    });
    Property prop = new Property();
    prop.setValue(versionValue);
    bindProperty(sourceDocument, versionAttributeSource, prop);
    // but just to make sure...
    if (prop.getValueGenerationStrategy() != null) {
        if (prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT) {
            throw new MappingException("'generated' attribute cannot be 'insert' for version/timestamp property", sourceDocument.getOrigin());
        }
    }
    if (versionAttributeSource.getUnsavedValue() != null) {
        versionValue.setNullValue(versionAttributeSource.getUnsavedValue());
    } else {
        versionValue.setNullValue("undefined");
    }
    rootEntityDescriptor.setVersion(prop);
    rootEntityDescriptor.setDeclaredVersion(prop);
    rootEntityDescriptor.addProperty(prop);
}
Also used : VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) Identifier(org.hibernate.boot.model.naming.Identifier) 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 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)1 VersionAttributeSource (org.hibernate.boot.model.source.spi.VersionAttributeSource)1 Property (org.hibernate.mapping.Property)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)1