Skip to content

feat: Support adding @YdbType annotation to method parameters #173

@zdazzy

Description

@zdazzy

To cover the following (and all similar) case:

interface MyRepository extends ListCrudRepository<MyEntity, String> {

    @Query(
        """
        SELECT <....>
        <....>
        LIMIT :limit
        """
    )
    List<MyEntity> findWithLimit(@Param("limit") long limit);

}

The inferred limit parameter type here is Int64, while YDB requires it to be exaclty UInt64.

There are other cases where implicit type conversion fails. So a way to control this behavior would be great. An existing @YdbType annotation seems like a good solution.

Activity

mipo256

mipo256 commented on Feb 17, 2025

@mipo256
Contributor

@zdazzy Existing YdbMappingJdbcConverter should solve this. This custom JdbcConverter is applied on both named and positional parameters.

Have you extended the AbstractYdbJdbcConfiguration?

zdazzy

zdazzy commented on Feb 20, 2025

@zdazzy
Author

@mipo256 The annotation is currently only applicable to fields. Placing it on method parameter will result in a compilation error.
The issue has nothing to do with configuration.

mipo256

mipo256 commented on Feb 21, 2025

@mipo256
Contributor

Yes, I got the general idea of what you're trying to do.

CC: @KirillKurdyukov please, add the pending-design tag for the issue

mipo256

mipo256 commented on Feb 21, 2025

@mipo256
Contributor

The first top-level review of the problem unravels the following approach.

We can specify the custom RepositoryFactoryBeanSupport in the @EnableJdbcRepositories, extended from JdbcRepositoryFactoryBean likely. We need it to override the creation of the JdbcRepositoryFactory child that has it's own QueryLookupStrategy defined. And here, we can construct our own QueryMethod with our own implementation of getParameters().

That would solve the problem. However, there are a couple of caveats.

  1. This would require to extend a lot of stuff from the original Spring Data Commons/Spring Data JDBC infrastructure. That is generally not a big deal, since it is designed in this way specifically
  2. The larger problem is that the JdbcQueryLookupStrategy that is native to Spring Data JDBC, like CreateIfNotFoundQueryLookupStrategy, which is used by default, is not a public API. Therefore, we would have to extend RelationalQueryLookupStrategy and duplicate some code from the original source tree.

So, we need to think about it more deeply.

CC: @KirillKurdyukov

mipo256

mipo256 commented on Feb 21, 2025

@mipo256
Contributor
mipo256

mipo256 commented on Mar 14, 2025

@mipo256
Contributor

UPDATE: After discussion with Spring Data team: The corresponding Spring Data JDBC change would be introduced in 4.0.x major release. When this will be done, we'll be able to implement this feature.

CC: @zdazzy @KirillKurdyukov

KirillKurdyukov

KirillKurdyukov commented on Mar 17, 2025

@KirillKurdyukov
Collaborator

UPDATE: After discussion with Spring Data team: The corresponding Spring Data JDBC change would be introduced in 4.0.x major release. When this will be done, we'll be able to implement this feature.

CC: @zdazzy @KirillKurdyukov

Thanks Misha!

added a commit that references this issue on Mar 21, 2025

1 remaining item

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @zdazzy@KirillKurdyukov@mipo256

    Issue actions

      feat: Support adding @YdbType annotation to method parameters · Issue #173 · ydb-platform/ydb-java-dialects