Skip to content

Call to id instead of elementId for assigned ids #2809

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
meistermeier opened this issue Oct 12, 2023 · 2 comments
Closed

Call to id instead of elementId for assigned ids #2809

meistermeier opened this issue Oct 12, 2023 · 2 comments
Assignees
Labels
status: needs-investigation An issue that has been triaged but needs further investigation type: enhancement A general enhancement

Comments

@meistermeier
Copy link
Collaborator

meistermeier commented Oct 12, 2023

Given the right Cypher dialect for NEO4J_5 was set, Spring Data Neo4j will still produce id calling queries and it might not be needed to do so.

UNWIND $__relationships__ AS relationship WITH relationship
MATCH (startNode:`Game`) WHERE startNode.appId = relationship.fromId
MATCH (endNode) WHERE **id(endNode)** = relationship.toId 
MERGE (startNode)-[relProps:`CATEGORIES`]->(endNode) RETURN elementId(relProps) AS __elementId__

For the parameters this line

return !targetEntity.isUsingDeprecatedInternalId() && targetEntity.isUsingInternalIds() && rendererRendersElementId(renderer);
makes elementIds for assigned ids not usable in generated queries for relationships.
The statement targetEntity.isUsingInternalIds() resolves to false and will always trigger the id fallback for
relatedInternalId = TemplateSupport.rendererCanUseElementIdIfPresent(renderer, targetEntity) ? savedEntity.elementId() : savedEntity.id();

The query generator side

.where(getEndNodeIdFunction((Neo4jPersistentEntity<?>) relationship.getTarget()).apply(endNode).isEqualTo(Cypher.property(row, Constants.TO_ID_PARAMETER_NAME)))

or to be more precise the logic inside
private static Function<Node, Expression> getEndNodeIdFunction(@Nullable Neo4jPersistentEntity<?> entity) {
Function<Node, Expression> startNodeIdFunction;
if (entity == null) {
return Functions::elementId;
}
if (!entity.isUsingDeprecatedInternalId() && entity.isUsingInternalIds()) {
startNodeIdFunction = Functions::elementId;
} else {
startNodeIdFunction = Functions::id;
}
return startNodeIdFunction;
}

has the same behaviour.

I don't know the reason why I decided to go this route and this needs some deeper analysis of why this is happening.

Thanks to @pbauerochse for reporting this.

@meistermeier meistermeier added status: needs-investigation An issue that has been triaged but needs further investigation type: enhancement A general enhancement labels Oct 12, 2023
@meistermeier meistermeier self-assigned this Oct 26, 2023
meistermeier added a commit that referenced this issue Nov 2, 2023
meistermeier added a commit that referenced this issue Nov 2, 2023
* Avoid using the outdated id function wherever possible.
* Never fall back to `toString(id((element))` (in Neo4j 4.4 scenarios)

Closes #2809
@meistermeier
Copy link
Collaborator Author

Version for testing: 7.2.0-GH-2809-SNAPSHOT

  <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>

@pbauerochse
Copy link

Seems to be fixed with your snapshot version. Thanks Gerrit

meistermeier added a commit that referenced this issue Nov 9, 2023
* Avoid using the outdated id function wherever possible.
* Never fall back to `toString(id((element))` (in Neo4j 4.4 scenarios)

Closes #2809
@meistermeier meistermeier added this to the 7.1.6 (2023.0.6) milestone Nov 9, 2023
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 type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants