[JAVA-2453] Manually ID'd Versioned Entities are not Optimistically Locked Created: 20/Feb/17  Updated: 21/Feb/17  Resolved: 21/Feb/17

Status: Closed
Project: Java Driver
Component/s: Write Operations
Affects Version/s: 3.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Sage M Pierce Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

For Entities that have non DB-Generated IDs, "Saves" to the DB are not optimistically locked. For example, it is possible to have two Versioned Entities with the same primary key and null versions and one will overwrite the other. This is undesirable when primary keys are meaningful and meaningful data is associated with the Entity.

This behavior is exposed by the following test:

{{
@Test(expected = ConcurrentModificationException.class)
public void testManuallyVersionedConcurrentModification()

{ final String id = UUID.randomUUID().toString(); final ManuallyVersionedEntity entity1 = new ManuallyVersionedEntity(); final ManuallyVersionedEntity entity2 = new ManuallyVersionedEntity(); entity1.setId(id); entity2.setId(id); getDs().save(entity1); getDs().save(entity2); }

}}



 Comments   
Comment by Ross Lawley [ 21/Feb/17 ]

Hi Sage-Pierce,

Firstly, thank you for the ticket and the PR, it will be followed up on Github. As this project is for the Mongo Java Driver only I'm marking it as "won't fix" - this only due to the context of this Jira Project.

As you may have noticed Morphia is supported via Github issues and Pull requests directly and your PR will be followed up there.

Thanks again,

Ross

Comment by Sage M Pierce [ 20/Feb/17 ]

Created PR here: https://github.com/mongodb/morphia/pull/1152

Generated at Thu Feb 08 08:57:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.