Skip to content

Relationship ID of saved instance is null #2904

@jk-tagbangers

Description

@jk-tagbangers

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions