Interface MutabilityPlan<T>
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
ArrayMutabilityPlan
,AttributeConverterMutabilityPlanImpl
,BlobJavaType.BlobMutabilityPlan
,CalendarJavaType.CalendarMutabilityPlan
,ClobJavaType.ClobMutabilityPlan
,CompositeUserTypeJavaTypeWrapper.MutabilityPlanWrapper
,DateJavaType.DateMutabilityPlan
,DiscriminatedAssociationAttributeMapping.MutabilityPlanImpl
,FormatMapperBasedJavaType
,Immutability
,ImmutableMutabilityPlan
,ImmutableObjectArrayMutabilityPlan
,JdbcDateJavaType.DateMutabilityPlan
,JdbcTimeJavaType.TimeMutabilityPlan
,JdbcTimestampJavaType.TimestampMutabilityPlan
,JsonJavaType
,MutableMutabilityPlan
,NClobJavaType.NClobMutabilityPlan
,SerializableJavaType.SerializableMutabilityPlan
,UserTypeJavaTypeWrapper.MutabilityPlanWrapper
,UserTypeMutabilityPlanAdapter
,XmlJavaType
Describes the mutability aspects of a given Java type.
Mutable values require special handling that is not necessary for immutable values:
- a mutable value must be cloned when taking a "snapshot" of the state of an entity for dirty-checking, and
- a mutable value requires more careful handling when the entity is disassembled for storage in destructured form in the second-level cache.
Neither is a requirement for correctness when dealing with an immutable
object. But there might be other reasons why an immutable object requires
custom implementations of disassemble(T, org.hibernate.SharedSessionContract)
and assemble(java.io.Serializable, org.hibernate.SharedSessionContract)
.
For example:
- if the object is not serializable, we might convert it to a serializable format,
- if the object hold a reference to an entity, we must replace that reference with an identifier, or
- if the object hold a reference to some heavyweight resource, we must release it.
For an immutable type, it's not usually necessary to do anything special
in deepCopy(T)
. The method can simply return its argument.
- See Also:
- API Note:
- The term "mutability" refers to the fact that, in general, the aspects of the Java type described by this contract are determined by whether the Java type has mutable internal state.
-
Method Summary
Modifier and TypeMethodDescription@Nullable T
assemble
(@Nullable Serializable cached, SharedSessionContract session) Assemble a previously disassembled value.@Nullable T
Return a deep copy of the value.@Nullable Serializable
disassemble
(@Nullable T value, SharedSessionContract session) Return a disassembled representation of the value.boolean
Can the internal state of instances ofT
be changed?
-
Method Details
-
isMutable
boolean isMutable()Can the internal state of instances ofT
be changed?- Returns:
- True if the internal state can be changed; false otherwise.
-
deepCopy
Return a deep copy of the value.- Parameters:
value
- The value to deep copy- Returns:
- The deep copy.
-