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

Relationships not stored/deleted on update of node (Release >=7.1.0) #2728

Closed
rainerfriesen opened this issue May 24, 2023 · 3 comments
Closed
Assignees
Labels
status: needs-investigation An issue that has been triaged but needs further investigation

Comments

@rainerfriesen
Copy link

rainerfriesen commented May 24, 2023

After updating to Spring Boot Starter 3.1.0 (--> Spring Boot Starter Neo4j 7.1.0) the save or update of #nodes that have relationships leads to a deletion of existing relationships on the updated node and new relationships ##not being saved. Prior to 7.1.0 that was working as expected.

Expected Result:

The TestEntity1 is stored with a relation to TestEntity2 (stored as well)

Actual Result:

TestEntity1 and TestEntity2 are stored on the DB but no relation is created. (Previous existing relations would have been removed, not shown in test)

Test-setup to reproduce:

Example Entities:

@Node
public class TestEntity1 {

    @Id
    @GeneratedValue
    private Long id;

    @Property("value_one")
    private String valueOne;

    @Relationship("related_to")
    private TestEntity2 relatedEntity;

    public TestEntity1(Long id, String valueOne, TestEntity2 relatedEntity) {
        this.id = id;
        this.valueOne = valueOne;
        this.relatedEntity = relatedEntity;
    }
    public Long getId() {
        return id;
    }

    public TestEntity2 getRelatedEntity() {
        return relatedEntity;
    }
}
@Node
public class TestEntity2 {

    @Id
    @GeneratedValue
    private Long id;

    @Property("valueTwo")
    private String valueTwo;

    public TestEntity2(Long id, String valueTwo) {
        this.id = id;
        this.valueTwo = valueTwo;
    }
}

Repository:

public interface TestEntity1Repository extends Neo4jRepository<TestEntity1, Long> {
}

Test (using TestContainers):

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith(SpringExtension.class)
@ActiveProfiles("test")
class TestEntity1IT extends IntegrationTestBase {

    @Autowired
    private TestEntity1Repository testEntity1Repository;

    @Test
    public void test() {
        TestEntity2 t2 = new TestEntity2(null, "v2");
        TestEntity1 t1 = new TestEntity1(null, "v1", t2);

        TestEntity1 result = testEntity1Repository.save(t1);

        TestEntity1 freshRetrieved = testEntity1Repository.findById(result.getId()).get();

        Assertions.assertNotNull(result.getRelatedEntity());
        Assertions.assertNotNull(freshRetrieved.getRelatedEntity()); // FAILS!
    }

}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 24, 2023
@meistermeier
Copy link
Collaborator

Thanks for reporting this. Seems to be a problem but needs further investigation.
In the mean time, you could change the Cypher-DSL configuration to enforce the NEO4J_5 dialect like mentioned here: #2729 (comment)
Since I just came to this issue after looking at the other one, I did not change the configuration and it works as expected.

@meistermeier meistermeier self-assigned this May 26, 2023
@meistermeier meistermeier added status: needs-investigation An issue that has been triaged but needs further investigation and removed status: waiting-for-triage An issue we've not yet triaged labels May 26, 2023
meistermeier added a commit that referenced this issue May 26, 2023
meistermeier added a commit that referenced this issue May 26, 2023
meistermeier added a commit that referenced this issue May 26, 2023
meistermeier added a commit that referenced this issue May 30, 2023
Make sure we ignore invalid dialect config (i.e. we actually have neo4j 5, but are on 4 dialect in a crucial mapping path.
meistermeier added a commit that referenced this issue May 30, 2023
Make sure we ignore invalid dialect config (i.e. we actually have neo4j 5, but are on 4 dialect in a crucial mapping path.
@meistermeier meistermeier added this to the 7.1.1 (2023.0.1) milestone May 30, 2023
@meistermeier
Copy link
Collaborator

Thanks again @rainerfriesen for reporting this.
We fixed this for the upcoming 7.1.1 release (d890a65) and main (2a0435a).

@michael-simons
Copy link
Collaborator

Thanks from my side as well, @rainerfriesen for the good reports!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-investigation An issue that has been triaged but needs further investigation
Projects
None yet
Development

No branches or pull requests

4 participants