[hibernate-dev] AttributeConverter and internally mutable domain types
Steve Ebersole
steve at hibernate.org
Thu Sep 24 15:08:32 EDT 2015
Reference https://hibernate.atlassian.net/browse/HHH-10111
This comes down to the idea of a Type's mutability : can the thing's
internal state be changed? We use this for all kinds of optimizations. If
the internal state is not mutable, we know that "making a deep copy", for
example, is a simple matter of just returning the original. It also
affects how we dirty check it, how we (2nd level) cache it, etc.
So far we have assumed that types mapped using AttributeConverters are
immutable. However, this Jira is an example of where that breaks down.
I think for now we will have to assume that the AttributeConverter entity
type is mutable and build an appropriate MutabilityPlan. Moving forward I
think we should consider a means to allow developers
using AttributeConverter along with immutable state (which seems to be the
majority case) the option to somehow indicate that the converted-to type is
immutable which allows us to apply the more efficient plan. Thoughts on
the best way to achieve this latter part? I am initially thinking an
optional contract for the AttributeConverter impl itself to implement:
@Converter
class MyAttributeConverter
implements AttributeConverter<Name,String>,
HibernateAttributeConverter {
// normal AttributeConverter methods
/**
* HibernateAttributeConverter
*/
@Override
public boolean isMutable() {
return true;
}
}
Another option is to develop some annotations that are applied to the
AttributeConverter impl (much like the javax.persistence.Converter itself):
@Converter
@org.hibernate.annotations.MutableConvertedState(true|false)
class MyAttributeConverter implements AttributeConverter<Name,String> {
// normal AttributeConverter methods
}
More information about the hibernate-dev
mailing list