[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2162) Optimisitic Locking unusable with 1..N of Set or List

Christian Bauer (JIRA) noreply at atlassian.com
Fri Oct 20 17:19:05 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2162?page=comments#action_24924 ] 

Christian Bauer commented on HHH-2162:
--------------------------------------

You looked at the standard JIRA help documentation. This is not how we classify issues, but we can't really rewrite the documentation of the tool we are using. Until somebody confirms this as a real issue, it is minor. Once it is confirmed, we assign it the right priority until it is resolved. This is how we have been working for years, and we plan to continue doing this.


> 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: Patch

>   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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list