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

Steve Ebersole (JIRA) noreply at atlassian.com
Mon Nov 6 11:38:05 EST 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2162?page=all ]
     
Steve Ebersole closed HHH-2162:
-------------------------------

    Resolution: Rejected
     Assign To: Steve Ebersole

I am going to reject this patch.  First, I am pretty certain that the current underlying causes for HHH-1401 are exactly the same as for this issue (I am pretty sure the early bugs in determining when writes to PersistentCollection actually dirtied the collection caused parts of the issue there).  Secondly, the proposed patch here can actually cause unecessary reads from the database to resolve the containsAll() check.

So, see HHH-1401 for tracking purposes...

> 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
>     Assignee: Steve Ebersole
>     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