DATAGRAPH-413: ConcurrentModificationException occurs when trying to persist entity after modification outside of transaction
This commit is contained in:
@@ -178,6 +178,27 @@ public class ModificationOutsideOfTransactionTests extends EntityTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPropertyOutsideTransactionCanBePersistedThereafter()
|
||||
{
|
||||
Person p = persistedPerson( "Michael", 35 );
|
||||
p.setAge( 25 );
|
||||
assertEquals(25, p.getAge());
|
||||
|
||||
try (Transaction tx = neo4jTemplate.getGraphDatabase().beginTx()) {
|
||||
assertEquals( 35, nodeFor( p ).getProperty("age") );
|
||||
tx.success();
|
||||
}
|
||||
|
||||
p.persist();
|
||||
|
||||
try (Transaction tx = neo4jTemplate.getGraphDatabase().beginTx()) {
|
||||
assertEquals( 25, nodeFor( p ).getProperty("age") );
|
||||
tx.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithUninitializedCollectionFieldWithoutUnderlyingState() {
|
||||
Group group = new Group();
|
||||
|
||||
@@ -159,6 +159,15 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
|
||||
Object valueFromDb = null;
|
||||
if (template.transactionIsRunning()) {
|
||||
valueFromDb = unwrap(delegate.getValue(property, MappingPolicy.MAP_FIELD_DIRECT_POLICY));
|
||||
} else {
|
||||
// For Implicit Transactions, we need to create
|
||||
// a tx to ensure we get the correct previous value
|
||||
// otherwise the possibility of getting a concurrent
|
||||
// modification exception when next persisting may occur
|
||||
try (Transaction tx = template.getGraphDatabaseService().beginTx()) {
|
||||
valueFromDb = unwrap(delegate.getValue(property, MappingPolicy.MAP_FIELD_DIRECT_POLICY));
|
||||
tx.success();
|
||||
}
|
||||
}
|
||||
addDirty(property, valueFromDb, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user