Hi,
I think it should be symmetric because if that property takes part in the
Object equality (equals/hashCode),
then the entity will not be equal to itself after you persisted and loaded
it again from the database.
final Event event = doInJPA(entityManager -> {
Event _event = new Event();
entityManager.persist(_event);
return event;
});
doInJPA(entityManager -> {
assertEquals(event, entityManager.find(Event.class, event.getId()));
});
This can be a problem if the Entity is part of a Set/Map too.
Vlad
On Thu, Jan 7, 2016 at 3:15 PM, Gunnar Morling <gunnar(a)hibernate.org> wrote:
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
_______________________________________________
hibernate-dev mailing list
hibernate-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev