Skip to content

Derived delete queries not working for Spring Data JDBC #1334

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
LarsKaulen opened this issue Sep 20, 2022 · 3 comments
Closed

Derived delete queries not working for Spring Data JDBC #1334

LarsKaulen opened this issue Sep 20, 2022 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@LarsKaulen
Copy link

LarsKaulen commented Sep 20, 2022

I try implementing a repository using Spring Data JDBC as described in the documentation, using an (embedded) HSQL database.

When using derived delete queries (see Example 6 in the linked documentation), I encounter two issues:

  1. When trying to return the number of deleted records (domain class com.example.demo.db.User), I get a ClassCastException (java.lang.ClassCastException: com.example.demo.db.User cannot be cast to java.lang.Long).
  2. When using a query with either void or with the domain object as return type, the method successfully completes, but the record is never deleted. It looks like only a SELECT statement is performed on the database, but not the DELETE statement.

It doesn't matter if I try to remove by id or by a custom attribute of my entity.
The default void deleteById(Integer id) method and using custom queries (with the @Query annotation) both works.
For other queries (e.g. findByUsername) everything seems to work.

I have created a minimal reproducer to showcase the problem: when running the com.example.demo.db.UserRepositoryTest class, the tests using the default method or the explicit query methods (those with @Query) work, but those with the derived queries fail.

Is this a bug or do I misunderstand/misconfigure something?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2022
@schauder
Copy link
Contributor

Duplicate of #771

@schauder schauder marked this as a duplicate of #771 Sep 20, 2022
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2022
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2022
@LarsKaulen
Copy link
Author

LarsKaulen commented Sep 20, 2022

Hi @schauder I also saw this issue but there it is stated that

Derived delete/removeByXxx queries work as expected for return type void

which isn't the case in my example. And the exception for long return value was also different.

But I guess #771 has developed into an accumulative issue regarding this? Maybe as long as #771 isn't fixed, there should be a note in the documentation, that the given examples actually aren't working...

@gregturn gregturn added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 26, 2022
@gregturn
Copy link
Contributor

Duplicates #771.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants