Skip to content
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

Static interface methods should not be considered query methods [DATACMNS-939] #1394

spring-projects-issues opened this issue Nov 19, 2016 · 1 comment
in: repository type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Nov 19, 2016

Marc Pynaert opened DATACMNS-939 and commented

I have a table with a partition key on a date, and I'll mostly ever query only the last 2 days. Beyond that, the data is "dead", we only keep it for trace.

I'm using Java 8 in which you can set default implementation of methods in interfaces.

Here is what I'm trying to do:

public interface MyObjectRepository extends CassandraRepository<MyObject> {

     * @return the partition key dates that we consider contain "alive" data.
    static String[] getAlivePartitionKeys() {
        String[] searchedPartitionKeys = new String[2];
        LocalDate currentLocalDate = LocalDateUtils.getUtcLocalDate();
        searchedPartitionKeys[0] = LocalDateUtils.format(currentLocalDate);// today
        searchedPartitionKeys[1] = LocalDateUtils.format(currentLocalDate.minus(Period.ofDays(1)));// yesterday
        return searchedPartitionKeys;

    default MyObject findById(UUID id) {
        return findByPartitionKeyDateAndId(getAlivePartitionKeys(), sessionUUID);

    @Query("SELECT * FROM myobject WHERE partition_key_date IN (:partitionKeyDates) AND id = :id")
    MyObject findByPartitionKeyDateAndId(@NotNull @Param("partitionKeyDates") String[] partitionKeyDates, @NotNull @Param("id") UUID id);


(Note: The String[] seem to not be supported with the version 1.4.5 but should be supported in 1.5.0 from what I understood, but that's not the object of my request, I'm only trying to express the need)

Here's is what I'd like to do from my service:


And that call will automatically look on the last 2 days. Am I trying to do something bad?

The problem is, I get the following error:

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: declarative query methods are a todo

I'm looking for a way to tell him I dont want any query resolution for those methods...
I thought an annotation could be used to disable it. Or we could automatically detect its a "static" or "default" method. We would then only resolve the query if:

!method.isDefault() && !Modifier.isStatic(method.getModifiers())

Affects: 1.13 M1 (Ingalls), 1.12.5 (Hopper SR5)

Referenced from: pull request #185

Backported to: 1.13 RC1 (Ingalls), 1.12.6 (Hopper SR6)

Copy link

@spring-projects-issues spring-projects-issues commented Nov 20, 2016

Mark Paluch commented

This ticket describes rather a bug in our repository support.

Your static method is considered a query method because it is passed into query creation. default methods are already excluded from query creation and that's what we should do for static interface methods as well.

As a workaround, I propose extracting the static method into a utility class or just inline it into your default method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: repository type: bug
None yet

No branches or pull requests

2 participants