[hibernate-dev] Attribute converters and dirty checks

Gunnar Morling gunnar at hibernate.org
Thu Jan 7 08:15:21 EST 2016


Hi,

I have an entity with an attribute whose value is converted by means
of an attribute converter. The converter operations are not symmetric,
i.e. it's not guaranteed that

    value.equals( convertToEntityAttribute( convertToDatabaseColumn( value ) ) )

is true.

Question 1: Is such converter valid, or is it a requirement that its
operations are symmetric?

If this converter is valid, then I am curious whether the following
optimization could be applied.

Currently, the dirty checking is based on equality comparison of the
attribute value. During persist a deep copy of the entity attribute
array is made, which does the forth-and-back conversion above. If the
converter isn't symmetric, this may yield a value which is different
from the one in the entity attribute.

Then at dirty check, the entity attribute is compared to that value
resulting from deep-copying, causing the property to be considered
dirty, although the value to be stored in the database actually is the
same. Subsequently, an UPDATE will be issued which contains the same
column value as the previous INSERT.

So, question 2: Would it be feasible to do the dirty check based on
the converted value?

Thanks,

--Gunnar


More information about the hibernate-dev mailing list