Assumed that I have 2 entity. The first entity is parent of the second entity with one-to-many relation.
class Item {
String name;
Integer price;
}
class Order {
List<Item> items;
String customerName;
}
And I have repository defined like this:
interface OrderRepository extends JpaRepository<Order, Long>, QueryDslPredicateExecutor<Order> {
}
After that, I have a controller that automatically bind parameter to predicate like this:
@RestController
@RequestMapping(path = "/orders")
class OrderController {
@RequestMapping(method = RequestMethod.GET)
List<Order> list(@QuerydslPredicate Predicate predicate) {
return orderRepository.findAll(predicate);
}
}
So, I can query order from repository with a specific filter like this:
curl -XGET http://localhost/orders?customerName=John
The problem is that I cannot filter value inside a list. I also try http://localhost/orders?items.name=Bag but got NullPointerException
java.lang.NullPointerException
at org.springframework.util.ReflectionUtils.getField(ReflectionUtils.java:143) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.data.querydsl.binding.QuerydslPredicateBuilder.reifyPath(QuerydslPredicateBuilder.java:185) ~[spring-data-commons-1.11.4.RELEASE.jar:?]
...
So, the questions is, how can I filter value inside list with Spring JPA and Querydsl.
Note: I use spring boot 1.3.4 with querydsl-jpa 3.7.4
Thanks.
QuerydslPredicateBuilder#reifyPathwhich is it tries to access path ofitem.namebut the field ofListPath<QItem>don't have field name that causeNullPointerException. I'm also trying to implement it myself, but my knowledge to code base is very little. Any help would be appreciated.