Merge pull request #116 from jotomo/DATAGRAPH-368

Fix DATAGRAPH-368
This commit is contained in:
Michael Hunger
2013-07-13 14:13:54 -07:00
2 changed files with 25 additions and 1 deletions

View File

@@ -62,6 +62,26 @@ public class PropertyTests extends EntityTestBase {
getNodeState(p).getProperty("thought");
}
/**
* @see DATAGRAPH-368
* */
@Test
@Transactional
public void testSetTransientPropertyBeforePersist() {
Person p = new Person();
p.setThought("detached");
p.persist();
// test asserts that no NPE is thrown
}
@Test
@Transactional
public void testSetTransientPropertyAfterPersist() {
Person p = persistedPerson("Michael", 35);
p.setThought("attached");
assertEquals("Transient property should be saved in the entity", "attached", p.getThought());
}
@Test
@Transactional
public void testGetTransientPropertyFieldNotManaged() {

View File

@@ -137,7 +137,11 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
}
@Override
public Object setValue(final Field field, final Object newVal, MappingPolicy mappingPolicy) {
return setValue(property(field),newVal, mappingPolicy);
Neo4jPersistentProperty property = property(field);
if (property != null) {
return setValue(property, newVal, mappingPolicy);
}
return delegate.setValue(property, newVal, mappingPolicy);
}
private Neo4jPersistentProperty property(Field field) {