diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java index 02be4376ad..cfdd6874b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java @@ -284,12 +284,10 @@ public class PropertyBinder { prop.setGeneration( PropertyGeneration.parse( generated.toString().toLowerCase() ) ); } } - NaturalId naturalId = property != null ? - property.getAnnotation( NaturalId.class ) : - null; + NaturalId naturalId = property != null ? property.getAnnotation( NaturalId.class ) : null; if ( naturalId != null ) { NaturalIdMutability mutability = naturalId.mutability(); - if ( mutability == null ) { + if ( mutability == NaturalIdMutability.UNSPECIFIED ) { mutability = naturalId.mutable() ? NaturalIdMutability.MUTABLE : NaturalIdMutability.IMMUTABLE_CHECKED; diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java index 9ebb3bd5b8..96f7236db2 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -150,10 +150,12 @@ public class Property implements Serializable, MetaAttributable { // if the property mapping consists of all formulas, // make it non-updateable final boolean[] columnUpdateability = value.getColumnUpdateability(); - return updateable && ( - //columnUpdateability.length==0 || - !ArrayHelper.isAllFalse(columnUpdateability) - ); + final boolean isImmutableNaturalId = isNaturalIdentifier() + && ( NaturalIdMutability.IMMUTABLE.equals( getNaturalIdMutability() ) + || NaturalIdMutability.IMMUTABLE_CHECKED.equals( getNaturalIdMutability() ) ); + return updateable + && !isImmutableNaturalId + && !ArrayHelper.isAllFalse(columnUpdateability); } public boolean isInsertable() { @@ -174,7 +176,8 @@ public class Property implements Serializable, MetaAttributable { this.generation = generation; } - public void setUpdateable(boolean mutable) { + public void setUpdateable( + boolean mutable) { this.updateable = mutable; } @@ -324,4 +327,5 @@ public class Property implements Serializable, MetaAttributable { public void setNaturalIdMutability(NaturalIdMutability naturalIdMutability) { this.naturalIdMutability = naturalIdMutability; } + } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index 55ff479de3..2e0f7d304f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -37,6 +37,7 @@ import org.jboss.logging.Logger; import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.MappingException; +import org.hibernate.NaturalIdMutability; import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.spi.CascadeStyle; @@ -154,7 +155,7 @@ public class EntityMetamodel implements Serializable { propertySpan = persistentClass.getPropertyClosureSpan(); properties = new StandardProperty[propertySpan]; - List naturalIdNumbers = new ArrayList(); + List naturalIdNumbers = new ArrayList(); // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ propertyNames = new String[propertySpan]; propertyTypes = new Type[propertySpan]; @@ -195,7 +196,7 @@ public class EntityMetamodel implements Serializable { if ( prop.isNaturalIdentifier() ) { naturalIdNumbers.add( i ); - if ( prop.isUpdateable() ) { + if ( prop.isUpdateable() && NaturalIdMutability.MUTABLE.equals( prop.getNaturalIdMutability() ) ) { foundUpdateableNaturalIdProperty = true; } }