From 8d6dd38ffb4e561fd3e20722034a44372ae85c99 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 6 Jul 2013 15:54:33 +0200 Subject: [PATCH 1/2] DATAGRAPH-368 Add test demonstrating the issue. --- .../neo4j/aspects/support/PropertyTests.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/PropertyTests.java b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/PropertyTests.java index f27a7c4b5..29b86ee02 100644 --- a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/PropertyTests.java +++ b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/PropertyTests.java @@ -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() { From 6fa76bad3a26a41b1c74be7c5a96ecfea4bfaa10 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 13 Jul 2013 15:11:43 +0200 Subject: [PATCH 2/2] DATAGRAPH-368 Handle transient property on detached entity. In DetachedEntityState.setValue(), check if the property to save exists on the Neo4jPersistentEntity instance. If the property is marked transient, the property won't exist on the entity. In that case, forward the request to the delegate. --- .../data/neo4j/fieldaccess/DetachedEntityState.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DetachedEntityState.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DetachedEntityState.java index 2e95174ab..17713f5cc 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DetachedEntityState.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DetachedEntityState.java @@ -137,7 +137,11 @@ public class DetachedEntityState implements EntityState { } @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) {