[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2162?page=c...
]
Thom Park commented on HHH-2162:
--------------------------------
OK,
by looking at the change history I was able to discover that Christian changed the
severity from blocker to minor.
Would he care to share the reason?
The issue may be of 'minor' severity to running Hibernate, after all, something
other than a set or list might be used instead. However, how practical is that really?
Here is an application that heavily uses EJB3 and hibernate with many sets and lists and
is effectively unusable because of these merge issues.
How can that be considered a 'minor' issue?
Optimisitic Locking unusable with 1..N of Set or List
-----------------------------------------------------
Key: HHH-2162
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2162
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.ga
Environment: Core 3.2 GA
EM 3.2 GA
HSQLDB 1.8.0.2 in memory
Reporter: Olli Blackburn
Priority: Minor
Attachments: CollectionType.patch, Playpen.zip
Calling merge() on an unmodified entity with 1..N relationship using Set or List results
in the entity being marked dirty, its version number is increased and an SQL UPDATE
performed on it. This makes it impossible to achieve any kind of sensible concurrency in
our application which makes extensive use of detached objects.
See the attached test case (packaged as a complete eclipse 3.2 project). Set EJB3_HOME,
HIBERNATE_HOME and HSQLDB_HOME in your eclipse workspace preferences and then run the
included PojoTest launcher to see it run.
The test populates the DB, does a select by name, merge, merge and select by name again.
Each of these five steps is in its own Tx and entity manager. The test is repeated for
Set, Map and List. Interesting Map seems to work, but as our application doesn't use
Maps that's little comfort to us. The pojo is not being modified (by my code) between
the merge calls(), yet I get the following output (each print is before the commit
following the operation):
findByUniqueName: PojoHashSet4 version=2
merge: PojoHashSet4 version=2
merge: PojoHashSet4 version=3
findByUniqueName: PojoHashSet4 version=5
findByUniqueName: PojoHashMap4 version=0
merge: PojoHashMap4 version=0
merge: PojoHashMap4 version=0
findByUniqueName: PojoHashMap4 version=0
findByUniqueName: PojoArrayList4 version=0
merge: PojoArrayList4 version=0
merge: PojoArrayList4 version=1
findByUniqueName: PojoArrayList4 version=2
HHH-1401 and HHH-1668 seem like they might be related to my problem, but debugging my
test case shows otherwise. The problem seems to be caused by the replacement of the empty
collection with a new empty collection. More specifically, the empty target collection is
cleared, marking it dirty, even though it contains no members is is about to have nothing
copied in it. This occurs in org.hibernate.type.CollectionType.replaceElements().
Looking at the code paths I think the problem runs deeper than my empty collection case.
If the source and target being copied by replaceElements() are identical (whether zero
length or not), the target will be marked dirty due to the result.clear() call in
replaceElements(). It seems there needs to be a pre-check for this case to avoid the whole
clear and copy process with it's associated setting of "dirtiness".
I'm attaching a patch for CollectionType which fixes the problem in the testing
we've performed.
Feedback and comments appreciated.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira