fix: Use direction as part of the node collection name for each relationship.
This avoids having duplicate keys in the map projection used to collect the nodes for each relationship in cases where a node has two relationships with the same name to the same label in different directions. Fixes #2918. Co-authored-by: Mathias Kühn <kuehn@synerva.de>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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<FailureRelationship> upstreamFailures;
|
||||
|
||||
@Relationship(type = "CAUSES", direction = Relationship.Direction.OUTGOING)
|
||||
public Set<FailureRelationship> downstreamFailures;
|
||||
}
|
||||
@@ -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<ConditionNode, String> {
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user