Skip to content

Usage of findByIdOrNull Kotlin extension ignores proxy annotations #3326

@GFriedrich

Description

@GFriedrich

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions