Skip to content

Same node with double Relationship not saved correctly #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VladoKuruc opened this issue Mar 22, 2021 · 2 comments
Closed

Same node with double Relationship not saved correctly #2196

VladoKuruc opened this issue Mar 22, 2021 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@VladoKuruc
Copy link

VladoKuruc commented Mar 22, 2021

I have issue with saving node with multiple relationships (with diferent properties) with the same target node. Repository save() method only save last relationship.

To report this issue, I created this test case (test added to org.springframework.data.neo4j.integration.imperative.RepositoryIT.RelationshipProperties)

	@Test
	void saveSameNodeWithDoubleRelationship(@Autowired HobbyWithRelationshipWithPropertiesRepository repository) {
		AltHobby hobby = new AltHobby();
		hobby.setName("Music");

		AltPerson altPerson = new AltPerson("Freddie");

		AltLikedByPersonRelationship rel1 = new AltLikedByPersonRelationship();
		rel1.setRating(5);
		rel1.setAltPerson(altPerson);

		AltLikedByPersonRelationship rel2 = new AltLikedByPersonRelationship();
		rel2.setRating(1);
		rel2.setAltPerson(altPerson);

		hobby.getLikedBy().add(rel1);
		hobby.getLikedBy().add(rel2);
		repository.save(hobby);

		hobby = repository.loadFromCustomQuery(altPerson.getId());
		assertThat(hobby.getName()).isEqualTo("Music");
		List<AltLikedByPersonRelationship> likedBy = hobby.getLikedBy();
		assertThat(likedBy).hasSize(2);

		assertThat(likedBy).containsExactlyInAnyOrder(rel1, rel2);
		}

I try it with SDN 6.0.x and master branch.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 22, 2021
@meistermeier meistermeier self-assigned this Mar 22, 2021
@meistermeier meistermeier added bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2021
@meistermeier
Copy link
Collaborator

Thanks for reporting it. I can reproduce it and thinking about how to solve the problem.
SDN wants to create both relationship code-wise but this is done in a MERGE statement. Since both relationships point towards the same entity, this is a little bit more tricky.
The underlying "blocker" is that we a very cautious when handling relationships with properties because we don't want to remove in the graph existing properties.

meistermeier added a commit that referenced this issue Mar 23, 2021
meistermeier added a commit that referenced this issue Mar 24, 2021
Relationship properties based relationships were overwritten due
to multiple `MERGE` statements if they had the same target node.
meistermeier added a commit that referenced this issue Mar 24, 2021
Relationship properties based relationships were overwritten due
to multiple `MERGE` statements if they had the same target node.
@meistermeier
Copy link
Collaborator

Fixed with merge of GH-2198

@michael-simons michael-simons added type: bug A general bug and removed bug labels Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants