diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/RelationshipDescription.java b/src/main/java/org/springframework/data/neo4j/core/mapping/RelationshipDescription.java index 55a986fdc..ead1a9f64 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/RelationshipDescription.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/RelationshipDescription.java @@ -115,7 +115,7 @@ public interface RelationshipDescription { @NonNull default String generateRelatedNodesCollectionName(NodeDescription mostAbstractNodeDescription) { - return this.getSource().getMostAbstractParentLabel(mostAbstractNodeDescription) + "_" + this.getType() + "_" + this.getTarget().getPrimaryLabel(); + return this.getSource().getMostAbstractParentLabel(mostAbstractNodeDescription) + "_" + this.getType() + "_" + this.getTarget().getPrimaryLabel() + "_" + this.isOutgoing(); } /** diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java b/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java index 01a7ae35b..9c38231eb 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java @@ -18,6 +18,7 @@ package org.springframework.data.neo4j.integration.issues; import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.tuple; import java.util.ArrayList; @@ -148,6 +149,8 @@ import org.springframework.data.neo4j.integration.issues.gh2819.GH2819Repository import org.springframework.data.neo4j.integration.issues.gh2886.Apple; import org.springframework.data.neo4j.integration.issues.gh2886.FruitRepository; import org.springframework.data.neo4j.integration.issues.gh2886.Orange; +import org.springframework.data.neo4j.integration.issues.gh2918.ConditionNode; +import org.springframework.data.neo4j.integration.issues.gh2918.ConditionRepository; import org.springframework.data.neo4j.integration.issues.qbe.A; import org.springframework.data.neo4j.integration.issues.qbe.ARepository; import org.springframework.data.neo4j.integration.issues.qbe.B; @@ -1081,6 +1084,18 @@ class IssuesIT extends TestBase { assertThat(fruits).allMatch(f -> f instanceof Apple || f instanceof Orange); } + @Test + @Tag("GH-2918") + void loadCycleFreeWithInAndOutgoingRelationship(@Autowired ConditionRepository conditionRepository) { + + var conditionSaved = conditionRepository.save(new ConditionNode()); + + // Condition has both an incoming and outgoing relationship typed CAUSES that will cause a duplicate key + // in the map projection for the relationships to load. The fix was to indicate the direction in the name + // used for projecting the relationship, too + assertThatNoException().isThrownBy(() -> conditionRepository.findById(conditionSaved.uuid)); + } + @Configuration @EnableTransactionManagement @EnableNeo4jRepositories(namedQueriesLocation = "more-custom-queries.properties") diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/ConditionNode.java b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/ConditionNode.java new file mode 100644 index 000000000..8cdc0232e --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/ConditionNode.java @@ -0,0 +1,40 @@ +/* + * Copyright 2011-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.integration.issues.gh2918; + +import java.util.Set; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; +import org.springframework.data.neo4j.core.schema.Relationship; +import org.springframework.data.neo4j.core.support.UUIDStringGenerator; + +/** + * @author Mathias Kühn + */ +@Node +public class ConditionNode { + @Id + @GeneratedValue(UUIDStringGenerator.class) + public String uuid; + + @Relationship(type = "CAUSES", direction = Relationship.Direction.INCOMING) + public Set upstreamFailures; + + @Relationship(type = "CAUSES", direction = Relationship.Direction.OUTGOING) + public Set downstreamFailures; +} diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/ConditionRepository.java b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/ConditionRepository.java new file mode 100644 index 000000000..82cf2c7d6 --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/ConditionRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2011-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.integration.issues.gh2918; + +import org.springframework.data.neo4j.repository.Neo4jRepository; + +/** + * @author Mathias Kühn + */ +public interface ConditionRepository extends Neo4jRepository { +} diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/FailureNode.java b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/FailureNode.java new file mode 100644 index 000000000..2827d8460 --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/FailureNode.java @@ -0,0 +1,31 @@ +/* + * Copyright 2011-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.integration.issues.gh2918; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; +import org.springframework.data.neo4j.core.support.UUIDStringGenerator; + +/** + * @author Mathias Kühn + */ +@Node +public class FailureNode { + @Id + @GeneratedValue(UUIDStringGenerator.class) + public String uuid; +} diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/FailureRelationship.java b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/FailureRelationship.java new file mode 100644 index 000000000..a5fd6e6b9 --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/gh2918/FailureRelationship.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.integration.issues.gh2918; + +import org.springframework.data.neo4j.core.schema.RelationshipId; +import org.springframework.data.neo4j.core.schema.RelationshipProperties; +import org.springframework.data.neo4j.core.schema.TargetNode; + +/** + * @author Mathias Kühn + */ +@RelationshipProperties +public abstract class FailureRelationship { + + @RelationshipId + public Long id; + + @TargetNode + public FailureNode target; +}