Skip to content

findByIdIn using id() function instead of elementId() #2879

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
luisfvieirasilva opened this issue Mar 15, 2024 · 1 comment
Closed

findByIdIn using id() function instead of elementId() #2879

luisfvieirasilva opened this issue Mar 15, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@luisfvieirasilva
Copy link

Hi, first of all, thanks for the project!

If I'm not doing anything wrong, I've found a bug during the query creation where it's using Neo4J's id() function instead of elementId() when I'm defining queries by their names on an interface repository.

Here it's the relevant entity and repository that I'm creating:

@Node(PostEntity.N_POST)
data class PostEntity(
    @Property(P_TITLE) val title: String,
    @Property(P_BODY) val body: String,
    @Relationship(R_POSTED, direction = Relationship.Direction.INCOMING) val postedBy: UserEntity,
    @Relationship(
        R_REACTED,
        direction = Relationship.Direction.INCOMING
    ) var reactedBy: Set<UserReactionRelationship> = emptySet(),
    @Property(P_CREATED_AT) @CreatedDate val createdAt: LocalDateTime? = null,
    @Id @GeneratedValue val id: String? = null
) {
    companion object {
        const val N_POST = "Post"
        const val P_TITLE = "title"
        const val P_BODY = "body"
        const val P_CREATED_AT = "createdAt"
        const val R_POSTED = "POSTED"
        const val R_REACTED = "REACTED"
    }

    fun withId(id: String): PostEntity {
        if (this.id === id) {
            return this;
        }

        return this.copy(id = id)
    }
}
interface PostRepository : Neo4jRepository<PostEntity, String> {

    fun findByPostedByUsernameIn(usernames: List<String>): List<PostEntity>

    fun findByIdIn(ids: List<String>): List<PostEntity>

    fun findByPostedByIdIn(ids: List<String>): List<PostEntity>

    fun findByReactedByIdIn(ids: List<String>): List<PostEntity>
}

The query findByPostedByUsernameIn works fine, but the others don't. Here's the log (debug mode) messages related to this query

2024-03-15T15:53:28.607-03:00 DEBUG 1837551 --- [nio-8080-exec-1] o.s.data.neo4j.cypher-normal             : Executing:
MATCH (postEntity:`Post`) WHERE id(postEntity) IN $ids RETURN postEntity{.body, .createdAt, .title, __nodeLabels__: labels(postEntity), __elementId__: elementId(postEntity), Post_POSTED_User: [(postEntity)<-[:`POSTED`]-(postEntity_postedBy:`User`) | postEntity_postedBy{.createdAt, .name, .username, __nodeLabels__: labels(postEntity_postedBy), __elementId__: elementId(postEntity_postedBy)}], Post_REACTED_User: [(postEntity)<-[Post__relationship__User:`REACTED`]-(postEntity_reactedBy:`User`) | postEntity_reactedBy{.createdAt, .name, .username, __nodeLabels__: labels(postEntity_reactedBy), __elementId__: elementId(postEntity_reactedBy), Post__relationship__User}]}
2024-03-15T15:56:11.924-03:00  WARN 1837551 --- [nio-8080-exec-2] o.s.data.neo4j.cypher.deprecation        : Neo.ClientNotification.Statement.FeatureDeprecationWarning: This feature is deprecated and will be removed in future versions.
	MATCH (postEntity:`Post`) WHERE id(postEntity) IN $ids RETURN postEntity{.body, .createdAt, .title, __nodeLabels__: labels(postEntity), __elementId__: elementId(postEntity), Post_POSTED_User: [(postEntity)<-[:`POSTED`]-(postEntity_postedBy:`User`) | postEntity_postedBy{.createdAt, .name, .username, __nodeLabels__: labels(postEntity_postedBy), __elementId__: elementId(postEntity_postedBy)}], Post_REACTED_User: [(postEntity)<-[Post__relationship__User:`REACTED`]-(postEntity_reactedBy:`User`) | postEntity_reactedBy{.createdAt, .name, .username, __nodeLabels__: labels(postEntity_reactedBy), __elementId__: elementId(postEntity_reactedBy), Post__relationship__User}]}
	                                ^
The query used a deprecated function: `id`.

Some important info:

  • findById works as expected, using elementId()
  • I have the bean configuring Dialect.NEO4J_5 (during the debug I made sure it's working properly)

After digging into the code, I believe the problem is at CypherQueryCreator.toCypherProperty method that doesn't check if it should use elementId() or id(). I planned to open a PR with a fix but since I don't now the code base and couldn't find an easy way to do a check similar to the one I've found here. So I decided to open this issue instead. Please lemme know if I'm missing something or if I can help fixing it!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 15, 2024
@meistermeier
Copy link
Collaborator

Thanks for reporting this and for your investigation. You nailed the place in the sources.
Currently working on a fix (and of course a test) for this.

@meistermeier meistermeier self-assigned this Apr 2, 2024
@meistermeier meistermeier added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 2, 2024
@meistermeier meistermeier added this to the 7.1.11 (2023.0.11) milestone Apr 2, 2024
meistermeier added a commit that referenced this issue Apr 2, 2024
There is a convenient function if the property in derived queries
refers to the internal id to use the `id` / `elementId` function.
This was never taken into consideration when the elementId support
got introduced.

The fix is straight forward in line with the existing call to
`Cypher.call("id")` to avoid introducing more changes to the
infrastructure.

Also includes fixture for the logging capture based tests around
elementId/id to catch the right log output again.

Closes #2879
meistermeier added a commit that referenced this issue Apr 2, 2024
There is a convenient function if the property in derived queries
refers to the internal id to use the `id` / `elementId` function.
This was never taken into consideration when the elementId support
got introduced.

The fix is straight forward in line with the existing call to
`Cypher.call("id")` to avoid introducing more changes to the
infrastructure.

Also includes fixture for the logging capture based tests around
elementId/id to catch the right log output again.

Closes #2879
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