Skip to content
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

Relationship ID of saved instance is null #2904

Closed
koyama-tagbangers opened this issue May 22, 2024 · 1 comment
Closed

Relationship ID of saved instance is null #2904

koyama-tagbangers opened this issue May 22, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@koyama-tagbangers
Copy link

koyama-tagbangers commented May 22, 2024

Version

spring-boot-starter-data-neo4j:3.2.5

Description

There is a problem that the @RelationshipId member is null in the return value of Neo4jOperations#save and CrudRepository#save.

But relationship ID of refetched node after saved is non null.

Is this the intended behavior?

Testing

I tried to test based on the official sample.

https://github.com/spring-projects/spring-data-neo4j/blob/main/src/test/java/org/springframework/data/neo4j/documentation/spring_boot/TemplateExampleTest.java

@Test
void relationshipIdOfSavedEntityShouldBeNonNull(@Autowired Neo4jTemplate neo4jTemplate) {
	MovieEntity movie = new MovieEntity("The Love Bug",
		"A movie that follows the adventures of Herbie, Herbie's driver, "
			+ "Jim Douglas (Dean Jones), and Jim's love interest, " + "Carole Bennett (Michele Lee)");

	Roles roles1 = new Roles(new PersonEntity(1931, "Dean Jones"), Collections.singletonList("Didi"));
	Roles roles2 = new Roles(new PersonEntity(1942, "Michele Lee"), Collections.singletonList("Michi"));
	movie.getActorsAndRoles().add(roles1);
	movie.getActorsAndRoles().add(roles2);

	MovieEntity result = neo4jTemplate.save(movie);
	assertThat(result.getActorsAndRoles()).allSatisfy(relationship -> {
		assertThat(relationship.getId()).isNotNull();
	});
}

This test fails because the relationship ID is null.

@Test
void relationshipIdOfFetchedEntityShouldBeNonNull(@Autowired Neo4jTemplate neo4jTemplate) {
	MovieEntity movie = new MovieEntity("The Love Bug",
		"A movie that follows the adventures of Herbie, Herbie's driver, "
			+ "Jim Douglas (Dean Jones), and Jim's love interest, " + "Carole Bennett (Michele Lee)");

	Roles roles1 = new Roles(new PersonEntity(1931, "Dean Jones"), Collections.singletonList("Didi"));
	Roles roles2 = new Roles(new PersonEntity(1942, "Michele Lee"), Collections.singletonList("Michi"));
	movie.getActorsAndRoles().add(roles1);
	movie.getActorsAndRoles().add(roles2);

	neo4jTemplate.save(movie);

	Optional<MovieEntity> result = neo4jTemplate.findById("The Love Bug", MovieEntity.class);
	assertThat(result).hasValueSatisfying(value -> {
		assertThat(value.getActorsAndRoles()).allSatisfy(relationship -> {
			assertThat(relationship.getId()).isNotNull();
		});
	});
}

On the other hand, the relationship ID of the fetched node is non null, so this test succeeds.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 22, 2024
@michael-simons michael-simons self-assigned this May 22, 2024
@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 22, 2024
@michael-simons
Copy link
Collaborator

Thanks for your report. This is a bug and a fix is under way.

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

3 participants