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);
}
Aggregations