Add support for deleteBy/removeBy queries
Since 2014, core Spring Data JPA has supported deleteBy/removeBy in queries, just like findBy queries. However, Spring Data Redis does not support this, instead throwing
java.lang.UnsupportedOperationException: Query method not supported.
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.doExecute(KeyValuePartTreeQuery.java:144)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:110)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:159)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:138)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at com.sun.proxy.$Proxy115.deleteByRecordingSid(Unknown Source)
I would like to request that deleteBy (and its synonym removeBy) be supported in queries.
Code Example
@RedisHash("Student")
public class Student {
@Id
private String id;
@Indexed
private String name;
// Getters and setters
}
@Repository
public interface StudentRepository extends CrudRepository<Student, String> {
Student findByName(String name);
void deleteByName(String name);
}
studentRepository.findByName("John Doe"); // Successful
studentRepository.deleteByName("John Doe"); // UnsupportedOperationException
Hi Thunderforge,
Please help me, I am facing deleteBy query above issue. Please do let me know how to resolve this. I have tried both deleteBy/removeBy. Getting same exception " Query method not supported" My table is Product having List of Brand (another table) attribute. I have created method as deleteByBrands_Id/removeByBrands_Id public class Product { @Id @Indexed private String id; @NonNull @Indexed private List<Brand> brands;
Note: Working fine for existsByBrands_Id/findByBrands_Id
@siddubai The reason I created this feature request is because spring-redis does not support this functionality.
The workaround is to do findByBrands() or whatever and then delete it. Definitely suboptimal, but until the functionality for a deleteByBrand() is implemented, that's all we can do.
@Thunderforge Thank you so much for your quick update :) Sorry to ask you, Did not get, using workaround(findByBrands) how can I delete it? Please elaborate.
@siddubai A delete() method is automatically generated by Spring when you use CrudRepository. What I'm saying is to do:
var product = productRepository.findByBrand("Brand X");
productRepository.delete(product);
// productRepository.deleteByBrand("Brand X"); // Doesn't work due to UnsupportedOperationException
@Thunderforge Now I got it, what you are trying to say. But my requirement is not to delete complete product. want to delete only one of the brand in product. (Similarly there are many nested objects.) Still is there any alternate workaround please do let me know. However thank you so much for your precious support.