Skip to content

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

@luisfvieirasilva

Description

@luisfvieirasilva

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!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions