diff --git a/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj b/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj index 28bb6102a..81ea66846 100644 --- a/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj +++ b/src/main/java/org/springframework/datastore/graph/neo4j/spi/node/Neo4jNodeBacking.aj @@ -1,6 +1,8 @@ package org.springframework.datastore.graph.neo4j.spi.node; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import java.util.*; @@ -159,13 +161,19 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields relationshipType, Relationship rel) { try { - final RelationshipBacked relationshipEntity = relationshipType.newInstance(); + final Constructor constructor = relationshipType.getDeclaredConstructor(); + constructor.setAccessible(true); + final RelationshipBacked relationshipEntity = constructor.newInstance(); relationshipEntity.setUnderlyingRelationship(rel); return relationshipEntity; } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e.getTargetException()); } } diff --git a/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj b/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj index b7817fe8b..7cd51a5f6 100644 --- a/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj +++ b/src/main/java/org/springframework/datastore/graph/neo4j/spi/relationship/Neo4jRelationshipBacking.aj @@ -121,7 +121,12 @@ public aspect Neo4jRelationshipBacking extends AbstractTypeAnnotatingMixinFields throw new InvalidDataAccessApiUsageException("Please set start node and end node before assigning to other fields."); } String propName = FieldAccessorFactory.getNeo4jPropertyName(f); - entity.getUnderlyingRelationship().setProperty(propName, newVal); + if (newVal==null) { + entity.getUnderlyingRelationship().removeProperty(propName); + } + else { + entity.getUnderlyingRelationship().setProperty(propName, newVal); + } log.info("SET " + f + " -> Neo4J simple relationship property [" + propName + "] with value=[" + newVal + "]"); return proceed(entity, newVal); }