Skip to content

Bug in connecting objects #2318

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
shayantabrizi opened this issue Jul 7, 2021 · 7 comments
Closed

Bug in connecting objects #2318

shayantabrizi opened this issue Jul 7, 2021 · 7 comments
Assignees
Labels
status: feedback-provided Feedback has been provided type: bug A general bug

Comments

@shayantabrizi
Copy link

It seems that there is something wrong which causes this code to behave nondeterministically and sometimes wrong.

        final C c = new C("att");
        final B b = new B(List.of(new B.C2(c)));
        final A a = new A(List.of(c), List.of(b));

        a.getCs().forEach(definition -> template.save(definition));
        a.getBs().forEach(definition -> template.save(definition));
        template.save(a);

        final Optional<Map<String, Object>> one = client.query("Match (n{id:'att'})-[r]-(m:A) return count(r)").fetch().one();
        System.out.println(one.get().get("count(r)"));

a has a member cs which includes a C object. However, sometimes a link is created between a and c (thus, printing 1) and sometimes no link is created between them (thus, printing 0).

Just run the code several times and see what is printed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 7, 2021
@meistermeier meistermeier self-assigned this Jul 8, 2021
@meistermeier
Copy link
Collaborator

meistermeier commented Jul 8, 2021

Could you please tell us which version are you using?

Edit: Found the link...nvm.

@meistermeier meistermeier added status: waiting-for-feedback We need additional information before we can continue 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 status: waiting-for-feedback We need additional information before we can continue status: needs-investigation An issue that has been triaged but needs further investigation labels Jul 8, 2021
@meistermeier
Copy link
Collaborator

I cannot really reproduce your issue. Always getting the relationship created without any changes to your code.
Speaking of which: you could skip the forEach definition parts because all the cascading relationship and nodes will get persisted during the template.save(a) call.
Maybe you can give me any hints how to enforce the faulty behaviour.

@shayantabrizi
Copy link
Author

shayantabrizi commented Jul 10, 2021

We have encountered it on three different computers. Windows and Linux. Neo4j 4.3.2 and 4.3.1 (embedded) and 4.2.1 (Neo4j Desktop).

The forEach parts were mentioned for reproducibility. But, I checked and without them the problem persists. I run on 4.2.1 (Neo4j Desktop) now and report the results:
First run: 1
Second run: 1
Third run: 0
Forth run: 1
Fifth run: 0
Sixth run: 0
Seventh run: 1

The results are non-deterministic. Maybe, a 0 happens in your system after several runs.
I committed the code I got the above results with now, in which the forEachs are removed.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 10, 2021
@meistermeier
Copy link
Collaborator

I can see the problem now. Just re-ran it and at least with a 30/70 ratio it is reproducible.
Investigating...

@meistermeier meistermeier added status: needs-investigation An issue that has been triaged but needs further investigation and removed status: feedback-provided Feedback has been provided labels Jul 12, 2021
meistermeier added a commit that referenced this issue Jul 12, 2021
@meistermeier
Copy link
Collaborator

meistermeier commented Jul 12, 2021

It would be helpful if you could give 6.1.3-GH-2318-SNAPSHOT a try.

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>6.1.3-GH-2318-SNAPSHOT</version>
</dependency>

To get the snapshot you would have to add Spring's repositories to your application:

<repositories>
  <repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/milestone</url>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
  <repository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>https://repo.spring.io/snapshot</url>
    <releases>
      <enabled>false</enabled>
    </releases>
  </repository>
</repositories>

@meistermeier meistermeier added status: waiting-for-feedback We need additional information before we can continue and removed status: needs-investigation An issue that has been triaged but needs further investigation labels Jul 12, 2021
@meistermeier meistermeier added this to the 6.1.3 (2021.0.3) milestone Jul 12, 2021
@meistermeier meistermeier added the type: bug A general bug label Jul 12, 2021
@shayantabrizi
Copy link
Author

It seems that the problem is solved. Thank you.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 13, 2021
@meistermeier
Copy link
Collaborator

Thanks for your feedback. Will merge this now into 6.1.x for the 6.1.3 patch and main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants