[hibernate-dev] AttributeConverter and internally mutable domain types

Sanne Grinovero sanne at hibernate.org
Fri Sep 25 05:56:44 EDT 2015


Hi Steve,
this could be a case for a marker interface?

We could introduce an "ImmutableAttributeConverter", to be implemented
by the safe ones, so that it doesn't break any existing converter.

On 24 September 2015 at 22:54, Steve Ebersole <steve at hibernate.org> wrote:
> 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
>> }
>>
>>
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev


More information about the hibernate-dev mailing list