Skip to content

Commit b77404d

Browse files
meistermeiermichael-simons
authored andcommitted
DATAGRAPH-1431 - Fix relationship mapping.
1 parent e7989df commit b77404d

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private Optional<Object> createInstanceOfRelationships(Neo4jPersistentProperty p
391391
mappedObjectHandler = (type, mappedObject) -> value.add(mappedObject);
392392
}
393393

394-
Value list = allValues.get(relationshipDescription.generateRelatedNodesCollectionName());
394+
Value list = values.get(relationshipDescription.generateRelatedNodesCollectionName());
395395

396396
List<Object> relationshipsAndProperties = new ArrayList<>();
397397

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import org.springframework.data.neo4j.integration.shared.common.PersonWithWither;
111111
import org.springframework.data.neo4j.integration.shared.common.Pet;
112112
import org.springframework.data.neo4j.integration.shared.common.SimilarThing;
113+
import org.springframework.data.neo4j.integration.shared.common.SimpleEntityWithRelationshipA;
113114
import org.springframework.data.neo4j.integration.shared.common.ThingWithAssignedId;
114115
import org.springframework.data.neo4j.integration.shared.common.ThingWithGeneratedId;
115116
import org.springframework.data.neo4j.integration.shared.common.WorksInClubRelationship;
@@ -1025,6 +1026,22 @@ void findEntityWithRelationshipWithAssignedId(@Autowired PetRepository repositor
10251026
assertThat(relatedThing.getName()).isEqualTo("Thing1");
10261027
}
10271028

1029+
@Test // DATAGRAPH-1431
1030+
void findAndMapMultipleLevelsOfSimpleRelationships(@Autowired SimpleEntityWithRelationshipARepository repository) {
1031+
Long aId = null;
1032+
try (Session session = createSession()) {
1033+
aId = session.writeTransaction(tx -> tx.run("CREATE (a:SimpleEntityWithRelationshipA)" +
1034+
"-[:TO_B]->(:SimpleEntityWithRelationshipB)" +
1035+
"-[:TO_C]->(:SimpleEntityWithRelationshipC)" +
1036+
" RETURN id(a) as aId").single().get("aId").asLong());
1037+
}
1038+
1039+
SimpleEntityWithRelationshipA entityA = repository.findById(aId).get();
1040+
assertThat(entityA).isNotNull();
1041+
assertThat(entityA.getBs()).hasSize(1);
1042+
assertThat(entityA.getBs().get(0).getCs()).hasSize(1);
1043+
}
1044+
10281045
}
10291046

10301047
@Nested
@@ -3322,6 +3339,8 @@ interface ParentRepository extends Neo4jRepository<ParentNode, Long> {
33223339
Optional<ExtendedParentNode> findExtendedParentNodeBySomeOtherAttribute(String someOtherAttribute);
33233340
}
33243341

3342+
interface SimpleEntityWithRelationshipARepository extends Neo4jRepository<SimpleEntityWithRelationshipA, Long> {}
3343+
33253344
@SpringJUnitConfig(Config.class)
33263345
static abstract class IntegrationTestBase {
33273346

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2011-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.shared.common;
17+
18+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
19+
import org.springframework.data.neo4j.core.schema.Id;
20+
import org.springframework.data.neo4j.core.schema.Node;
21+
import org.springframework.data.neo4j.core.schema.Relationship;
22+
23+
import java.util.List;
24+
25+
/**
26+
* @author Gerrit Meier
27+
*/
28+
@Node
29+
public class SimpleEntityWithRelationshipA {
30+
31+
@Id @GeneratedValue private Long id;
32+
33+
@Relationship("TO_B")
34+
private List<SimpleEntityWithRelationshipB> bs;
35+
36+
public List<SimpleEntityWithRelationshipB> getBs() {
37+
return bs;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2011-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.shared.common;
17+
18+
import java.util.List;
19+
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
import org.springframework.data.neo4j.core.schema.Relationship;
24+
25+
/**
26+
* @author Gerrit Meier
27+
*/
28+
@Node
29+
public class SimpleEntityWithRelationshipB {
30+
31+
@Id @GeneratedValue private Long id;
32+
33+
@Relationship("TO_C")
34+
private List<SimpleEntityWithRelationshipC> cs;
35+
36+
public List<SimpleEntityWithRelationshipC> getCs() {
37+
return cs;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2011-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.shared.common;
17+
18+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
19+
import org.springframework.data.neo4j.core.schema.Id;
20+
import org.springframework.data.neo4j.core.schema.Node;
21+
22+
/**
23+
* @author Gerrit Meier
24+
*/
25+
@Node
26+
public class SimpleEntityWithRelationshipC {
27+
28+
@Id @GeneratedValue private Long id;
29+
30+
}

0 commit comments

Comments
 (0)