File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed
main/java/org/hibernate/type/descriptor
test/java/org/hibernate/test/converter Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 9
9
import javax .persistence .AttributeConverter ;
10
10
11
11
import org .hibernate .type .AbstractSingleColumnStandardBasicType ;
12
+ import org .hibernate .type .descriptor .java .ImmutableMutabilityPlan ;
12
13
import org .hibernate .type .descriptor .java .JavaTypeDescriptor ;
13
14
import org .hibernate .type .descriptor .java .MutabilityPlan ;
14
15
import org .hibernate .type .descriptor .sql .SqlTypeDescriptor ;
@@ -32,8 +33,9 @@ public class AttributeConverterTypeAdapter<T> extends AbstractSingleColumnStanda
32
33
private final Class jdbcType ;
33
34
private final AttributeConverter <? extends T ,?> attributeConverter ;
34
35
35
- private final AttributeConverterMutabilityPlanImpl <T > mutabilityPlan ;
36
+ private final MutabilityPlan <T > mutabilityPlan ;
36
37
38
+ @ SuppressWarnings ("unchecked" )
37
39
public AttributeConverterTypeAdapter (
38
40
String name ,
39
41
String description ,
@@ -49,7 +51,10 @@ public AttributeConverterTypeAdapter(
49
51
this .jdbcType = jdbcType ;
50
52
this .attributeConverter = attributeConverter ;
51
53
52
- this .mutabilityPlan = new AttributeConverterMutabilityPlanImpl <T >( attributeConverter );
54
+ this .mutabilityPlan =
55
+ entityAttributeJavaTypeDescriptor .getMutabilityPlan ().isMutable () ?
56
+ new AttributeConverterMutabilityPlanImpl <T >( attributeConverter ) :
57
+ ImmutableMutabilityPlan .INSTANCE ;
53
58
54
59
log .debug ( "Created AttributeConverterTypeAdapter -> " + name );
55
60
}
Original file line number Diff line number Diff line change @@ -122,9 +122,19 @@ public <T> JavaTypeDescriptor<T> getDescriptor(Class<T> cls) {
122
122
123
123
public static class FallbackJavaTypeDescriptor <T > extends AbstractTypeDescriptor <T > {
124
124
@ SuppressWarnings ("unchecked" )
125
- protected FallbackJavaTypeDescriptor (Class <T > type ) {
126
- // MutableMutabilityPlan would be the "safest" option, but we do not necessarily know how to deepCopy etc...
127
- super ( type , ImmutableMutabilityPlan .INSTANCE );
125
+ protected FallbackJavaTypeDescriptor (final Class <T > type ) {
126
+ // MutableMutabilityPlan is the "safest" option, but we do not necessarily know how to deepCopy etc...
127
+ super (
128
+ type ,
129
+ new MutableMutabilityPlan <T >() {
130
+ @ Override
131
+ protected T deepCopyNotNull (T value ) {
132
+ throw new HibernateException (
133
+ "Not known how to deep copy value of type: [" + type .getName () + "]"
134
+ );
135
+ }
136
+ }
137
+ );
128
138
}
129
139
130
140
@ Override
Original file line number Diff line number Diff line change 14
14
15
15
import org .hibernate .Session ;
16
16
17
+ import org .hibernate .persister .entity .EntityPersister ;
17
18
import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
18
19
import org .junit .Test ;
19
20
20
21
import static org .junit .Assert .assertEquals ;
22
+ import static org .junit .Assert .assertFalse ;
23
+ import static org .junit .Assert .assertTrue ;
21
24
22
25
/**
23
26
* @author Steve Ebersole
@@ -109,6 +112,13 @@ public void dirtyCheckAgainstNewNumberInstance() {
109
112
session .close ();
110
113
}
111
114
115
+ @ Test
116
+ public void checkConverterMutabilityPlans () {
117
+ final EntityPersister persister = sessionFactory ().getEntityPersister ( SomeEntity .class .getName () );
118
+ assertFalse ( persister .getPropertyType ( "number" ).isMutable () );
119
+ assertTrue ( persister .getPropertyType ( "name" ).isMutable () );
120
+ }
121
+
112
122
@ Override
113
123
protected Class [] getAnnotatedClasses () {
114
124
return new Class [] {SomeEntity .class };
You can’t perform that action at this time.
0 commit comments