Skip to content

Commit

Permalink
GH-2124 - Fix failing save for uninitialized maps of dynamic properties.
Browse files Browse the repository at this point in the history
This closes #2124.
  • Loading branch information
michael-simons committed Jan 25, 2021
1 parent 461831d commit 767338b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public final class MappingSupport {
* list of related values)
*/
public static Collection<?> unifyRelationshipValue(Neo4jPersistentProperty property, Object rawValue) {

if (rawValue == null) {
return Collections.emptyList();
}

Collection<?> unifiedValue;
if (property.isDynamicAssociation()) {
if (property.isDynamicOneToManyAssociation()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -145,4 +146,32 @@ static class WeirdSource {
@Relationship(type = "ITS_COMPLICATED")
IrrelevantTargetContainer irrelevantTargetContainer;
}

@Node
@Getter @Setter
static class LonelySourceContainer {
@Id @GeneratedValue
private Long id;

@Relationship(type = "RELATIONSHIP_PROPERTY_CONTAINER")
RelationshipPropertyContainer single;

@Relationship(type = "RELATIONSHIP_PROPERTY_CONTAINER_2")
List<RelationshipPropertyContainer> multiNull;

@Relationship(type = "RELATIONSHIP_PROPERTY_CONTAINER_3")
List<RelationshipPropertyContainer> multiEmpty = new ArrayList<>();

@Relationship
Map<String, List<IrrelevantTargetContainer>> dynNullList;

@Relationship
Map<String, List<SimpleGeneratedIDPropertyContainer>> dynEmptyList = new HashMap<>();

@Relationship
Map<String, SimpleGeneratedIDPropertyContainerWithVersion> dynNullSingle;

@Relationship
Map<String, SimplePropertyContainer> dynEmptySingle = new HashMap<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ void customConvertersForRelsMustBeTakenIntoAccount() {
}
}

@Test // GH-2124
void shouldNotFailWithEmptyOrNullRelationshipProperties() {

DomainClasses.LonelySourceContainer s = template.save(new DomainClasses.LonelySourceContainer());
try (Session session = driver.session()) {
long cnt = session.run("MATCH (m) WHERE id(m) = $id RETURN count(m)", Collections.singletonMap("id", s.getId())).single().get(0).asLong();
assertThat(cnt).isEqualTo(1L);
}
}

@Configuration
@EnableTransactionManagement
static class Config extends AbstractNeo4jConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ void customConvertersForRelsMustBeTakenIntoAccount() {
}
}

@Test // GH-2124
void shouldNotFailWithEmptyOrNullRelationshipProperties() {

List<Long> recorded = new ArrayList<>();
template.save(new DomainClasses.LonelySourceContainer())
.map(DomainClasses.LonelySourceContainer::getId)
.as(StepVerifier::create)
.recordWith(() -> recorded)
.expectNextCount(1L)
.verifyComplete();
try (Session session = driver.session()) {
long cnt = session.run("MATCH (m) WHERE id(m) = $id RETURN count(m)", Collections.singletonMap("id", recorded.get(0))).single().get(0).asLong();
assertThat(cnt).isEqualTo(1L);
}
}

@Configuration
@EnableTransactionManagement
static class Config extends AbstractReactiveNeo4jConfig {
Expand Down

0 comments on commit 767338b

Please sign in to comment.