Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QueryDSL delete method

I'm using spring-data-mongodb 1.2.0 with QueryDSL 2.9.0.

Why doesn't the QueryDslPredicateExecutor have a delete(Predicate predicate) method?

Is there a workaround?

like image 472
Modi Avatar asked May 01 '13 09:05

Modi


1 Answers

What you can probably do is this. With the predicate for "where" condition, query for the objects and then pass that to the delete method

QMyObj obj= new QMyObj("myObj");
Iterable<MyObj> myObjs = myObjRepository.findAll(obj.property.eq("property"));
myObjRepository.delete(myObjs);

Here I am first creating an instance of the Q class and then finding all the objects based on the predicate. Then calling the repository's void delete(Iterable<? extends T> entities) method.

May be it is because of this workaround they don't provide it, but that is for the Spring Source guys to confirm

like image 141
Dhanush Gopinath Avatar answered Sep 28 '22 07:09

Dhanush Gopinath