spring-projects / spring-projects/spring-data-commons

Usage of findByIdOrNull Kotlin extension ignores proxy annotations

Open
#3,326 7 comments 2 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

Imagine you define a repository in Kotlin like:

@Repository
interface MyRepository : CrudRepository<MyObject, String> {
    @Cacheable("myCache")
    override fun findById(id: String): Optional<MyObject>
}

And you then try to use this repository with the extension function of findByIdOrNull, you'll find that the @Cacheable annotation is ignored.

This is due to the fact that the findByIdOrNull will proxy the request to the interface method of findById(Object) instead of findById(String).
As the first one doesn't have any annotation in place, the annotation on the overridden method is never used.

I'm wondering if making the extension an inline extension would already fix the problem (but I didn't try that).

Thanks for having a look into this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.