HHH-6970 - Expand notion of "natural id mutability" to ternary value

This commit is contained in:
Steve Ebersole 2012-01-20 09:31:55 -06:00
parent 73dec965a0
commit e0a09dbd79
3 changed files with 14 additions and 11 deletions

View File

@ -284,12 +284,10 @@ public class PropertyBinder {
prop.setGeneration( PropertyGeneration.parse( generated.toString().toLowerCase() ) ); prop.setGeneration( PropertyGeneration.parse( generated.toString().toLowerCase() ) );
} }
} }
NaturalId naturalId = property != null ? NaturalId naturalId = property != null ? property.getAnnotation( NaturalId.class ) : null;
property.getAnnotation( NaturalId.class ) :
null;
if ( naturalId != null ) { if ( naturalId != null ) {
NaturalIdMutability mutability = naturalId.mutability(); NaturalIdMutability mutability = naturalId.mutability();
if ( mutability == null ) { if ( mutability == NaturalIdMutability.UNSPECIFIED ) {
mutability = naturalId.mutable() mutability = naturalId.mutable()
? NaturalIdMutability.MUTABLE ? NaturalIdMutability.MUTABLE
: NaturalIdMutability.IMMUTABLE_CHECKED; : NaturalIdMutability.IMMUTABLE_CHECKED;

View File

@ -150,10 +150,12 @@ public class Property implements Serializable, MetaAttributable {
// if the property mapping consists of all formulas, // if the property mapping consists of all formulas,
// make it non-updateable // make it non-updateable
final boolean[] columnUpdateability = value.getColumnUpdateability(); final boolean[] columnUpdateability = value.getColumnUpdateability();
return updateable && ( final boolean isImmutableNaturalId = isNaturalIdentifier()
//columnUpdateability.length==0 || && ( NaturalIdMutability.IMMUTABLE.equals( getNaturalIdMutability() )
!ArrayHelper.isAllFalse(columnUpdateability) || NaturalIdMutability.IMMUTABLE_CHECKED.equals( getNaturalIdMutability() ) );
); return updateable
&& !isImmutableNaturalId
&& !ArrayHelper.isAllFalse(columnUpdateability);
} }
public boolean isInsertable() { public boolean isInsertable() {
@ -174,7 +176,8 @@ public class Property implements Serializable, MetaAttributable {
this.generation = generation; this.generation = generation;
} }
public void setUpdateable(boolean mutable) { public void setUpdateable(
boolean mutable) {
this.updateable = mutable; this.updateable = mutable;
} }
@ -324,4 +327,5 @@ public class Property implements Serializable, MetaAttributable {
public void setNaturalIdMutability(NaturalIdMutability naturalIdMutability) { public void setNaturalIdMutability(NaturalIdMutability naturalIdMutability) {
this.naturalIdMutability = naturalIdMutability; this.naturalIdMutability = naturalIdMutability;
} }
} }

View File

@ -37,6 +37,7 @@ import org.jboss.logging.Logger;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.NaturalIdMutability;
import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyle;
@ -154,7 +155,7 @@ public class EntityMetamodel implements Serializable {
propertySpan = persistentClass.getPropertyClosureSpan(); propertySpan = persistentClass.getPropertyClosureSpan();
properties = new StandardProperty[propertySpan]; properties = new StandardProperty[propertySpan];
List naturalIdNumbers = new ArrayList(); List<Integer> naturalIdNumbers = new ArrayList<Integer>();
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
propertyNames = new String[propertySpan]; propertyNames = new String[propertySpan];
propertyTypes = new Type[propertySpan]; propertyTypes = new Type[propertySpan];
@ -195,7 +196,7 @@ public class EntityMetamodel implements Serializable {
if ( prop.isNaturalIdentifier() ) { if ( prop.isNaturalIdentifier() ) {
naturalIdNumbers.add( i ); naturalIdNumbers.add( i );
if ( prop.isUpdateable() ) { if ( prop.isUpdateable() && NaturalIdMutability.MUTABLE.equals( prop.getNaturalIdMutability() ) ) {
foundUpdateableNaturalIdProperty = true; foundUpdateableNaturalIdProperty = true;
} }
} }