[hibernate-dev] AttributeConverter and internally mutable domain types

Steve Ebersole steve at hibernate.org
Thu Sep 24 16:54:57 EDT 2015


I went ahead and resolved HHH-10111 to be correct in the mutable cases as
well.  I created a new Jira[1] to continue the discussion related to
allowing the user to indicate that the type is immutable (as an
optimization), so let's move discussion of those follow-on steps to that
Jira.


[1] - https://hibernate.atlassian.net/browse/HHH-10127

On Thu, Sep 24, 2015 at 2:08 PM Steve Ebersole <steve at hibernate.org> wrote:

> 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