Hi,
The challenge is that both have merit.
The first one (dirty merge + dirty attached = exception) is more correct
from a consistency perspective.
The second one (dirty merge + dirty attached = dirty merge wins) wins is
(probably) usefull in many practical cases (and works like I think most
people thing merge works ...that you
are telling hibernate that the object to be merged in is the most correct
one).
As far as I remember from the last time we discussed it we considered
adding a MergeMode to
allow users to enable the "dirty merge wins" strategy.
The spec should list which one wins otherwise in this merge situations
otherwise merge's behavior is non-specfied across implementations which
will lead to alot of problems.
Have you tested it both in hibernate core and against entitymanager ? Do
they behave differently ?
/max
I wrote (tested and verified with Gavin):
Finally, merging doesn’t allow the following scenario, where two
modifications conflict on one snapshot:
item.getId() // The database identity is "1234"
item.setDescription(...);
Session session= sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Item item2 = (Item) session.get(Item.class, new Long(1234));
item2.setDescription(...); // Not allowed!
return session.merge(item); // Throws exception!
tx.commit();
session.close();
The detached object’s description is modified as well as the persistent
object’s. There is no way for Hibernate to determine who will win in
this situation and a StaleObjectStateException is thrown when you try to
merge() onto a dirty persistent instance.
Emmanuel comments:
No exception is raised in my tests. The merged state takes precedence
over the initially loaded and modified state (regardless the object has
been versioned or not) AFAIR, the spec does not talk about such an
exception either.
What is it?
_______________________________________________
hibernate-dev mailing list
hibernate-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev
--
--
Max Rydahl Andersen
callto://max.rydahl.andersen
Hibernate
max(a)hibernate.org
http://hibernate.org
JBoss a division of Red Hat
max.andersen(a)jboss.com