diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/converter/AttributeConverterTypeAdapter.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/converter/AttributeConverterTypeAdapter.java index fd1d145423..c30569aa10 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/converter/AttributeConverterTypeAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/converter/AttributeConverterTypeAdapter.java @@ -9,6 +9,7 @@ package org.hibernate.type.descriptor.converter; import javax.persistence.AttributeConverter; import org.hibernate.type.AbstractSingleColumnStandardBasicType; +import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; @@ -32,8 +33,9 @@ public class AttributeConverterTypeAdapter extends AbstractSingleColumnStanda private final Class jdbcType; private final AttributeConverter attributeConverter; - private final AttributeConverterMutabilityPlanImpl mutabilityPlan; + private final MutabilityPlan mutabilityPlan; + @SuppressWarnings("unchecked") public AttributeConverterTypeAdapter( String name, String description, @@ -49,7 +51,10 @@ public class AttributeConverterTypeAdapter extends AbstractSingleColumnStanda this.jdbcType = jdbcType; this.attributeConverter = attributeConverter; - this.mutabilityPlan = new AttributeConverterMutabilityPlanImpl( attributeConverter ); + this.mutabilityPlan = + entityAttributeJavaTypeDescriptor.getMutabilityPlan().isMutable() ? + new AttributeConverterMutabilityPlanImpl( attributeConverter ) : + ImmutableMutabilityPlan.INSTANCE; log.debug( "Created AttributeConverterTypeAdapter -> " + name ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java index 69a3d19e01..0e54c0c6dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptorRegistry.java @@ -122,9 +122,19 @@ public class JavaTypeDescriptorRegistry { public static class FallbackJavaTypeDescriptor extends AbstractTypeDescriptor { @SuppressWarnings("unchecked") - protected FallbackJavaTypeDescriptor(Class type) { - // MutableMutabilityPlan would be the "safest" option, but we do not necessarily know how to deepCopy etc... - super( type, ImmutableMutabilityPlan.INSTANCE ); + protected FallbackJavaTypeDescriptor(final Class type) { + // MutableMutabilityPlan is the "safest" option, but we do not necessarily know how to deepCopy etc... + super( + type, + new MutableMutabilityPlan() { + @Override + protected T deepCopyNotNull(T value) { + throw new HibernateException( + "Not known how to deep copy value of type: [" + type.getName() + "]" + ); + } + } + ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/DirtyCheckingTest.java b/hibernate-core/src/test/java/org/hibernate/test/converter/DirtyCheckingTest.java index 7c29212002..a38639e14b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/DirtyCheckingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/DirtyCheckingTest.java @@ -14,10 +14,13 @@ import javax.persistence.Id; import org.hibernate.Session; +import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Steve Ebersole @@ -109,6 +112,13 @@ public class DirtyCheckingTest extends BaseNonConfigCoreFunctionalTestCase { session.close(); } + @Test + public void checkConverterMutabilityPlans() { + final EntityPersister persister = sessionFactory().getEntityPersister( SomeEntity.class.getName() ); + assertFalse( persister.getPropertyType( "number" ).isMutable() ); + assertTrue( persister.getPropertyType( "name" ).isMutable() ); + } + @Override protected Class[] getAnnotatedClasses() { return new Class[] {SomeEntity.class};