HHH-7427 : Ensure version column is non-nullable

This commit is contained in:
Gail Badner 2012-07-03 16:19:03 -07:00
parent 6f23941c29
commit bc3964ba98
3 changed files with 12 additions and 4 deletions

View File

@ -1616,6 +1616,12 @@ private void bindVersion( final EntityBinding rootEntityBinding, final VersionAt
}
final EntityVersion version = rootEntityBinding.getHierarchyDetails().getEntityVersion();
version.setVersioningAttributeBinding( ( BasicAttributeBinding ) bindAttribute( rootEntityBinding, versionAttributeSource ) );
// ensure version is non-nullable
for ( RelationalValueBinding valueBinding : version.getVersioningAttributeBinding().getRelationalValueBindings() ) {
if ( valueBinding.getValue() instanceof Column ) {
( (Column) valueBinding.getValue() ).setNullable( false );
}
}
version.setUnsavedValue(
versionAttributeSource.getUnsavedValue() == null
? "undefined"

View File

@ -41,14 +41,12 @@ public class RelationalValueBinding {
private final boolean includeInInsert;
private final boolean includeInUpdate;
private final boolean isDerived;
private final boolean isNullable;
public RelationalValueBinding(final DerivedValue value) {
this.value = value;
this.includeInInsert = false;
this.includeInUpdate = false;
this.isDerived = true;
this.isNullable = true;
}
public RelationalValueBinding(final Column value, final boolean includeInInsert, final boolean includeInUpdate) {
@ -56,7 +54,6 @@ public RelationalValueBinding(final Column value, final boolean includeInInsert,
this.includeInInsert = includeInInsert;
this.includeInUpdate = includeInUpdate;
this.isDerived = false;
this.isNullable = value.isNullable();
}
/**
@ -83,7 +80,7 @@ public boolean isDerived() {
* @return {@code true} indicates the bound value is derived or a column not marked as non-null.
*/
public boolean isNullable() {
return isNullable;
return isDerived() || ( (Column) value ).isNullable();
}
/**

View File

@ -107,6 +107,11 @@ public void testSimpleVersionedEntityMapping() {
assertNotNull( entityBinding.getHierarchyDetails().getEntityVersion().getVersioningAttributeBinding() );
assertNotNull( entityBinding.getHierarchyDetails().getEntityVersion().getVersioningAttributeBinding().getAttribute() );
final BasicAttributeBinding versionAttributeBinding =
entityBinding.getHierarchyDetails().getEntityVersion().getVersioningAttributeBinding();
assertEquals( "does not have 1 relational binding", 1, versionAttributeBinding.getRelationalValueBindings().size() );
assertEquals( "version is nullable", false, versionAttributeBinding.getRelationalValueBindings().get( 0 ).isNullable() );
}
@Test