Skip to content

Cannot use Specification<T> interface to create subquery predicates #2689

Open
@pterjenvri

Description

@pterjenvri

I implemented numerous own Specification classes that implement the interface called Specification<T> in the org.springframework.data.jpa.domain package. This Specification<T> interface has a Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder); interface function which has to be implemented along with implementing the interface. This toPredicate function has 3 parameters, the Root<T>, the CriteriaQuery<?>, and the Criteriabuilder. As long as I want to create the Predicate object for a CriteriaQuery object it works fine. However I have cases, when I would like to use my own Specification classes to create Predicate objects for subqueries. As I have found out this is currently impossible because the toPredicate function requires CriteriaQuery object as its second parameter instead of requiring the common parent of CriteriaQuery<T> and Subquery<T> that could be AbstractQuery<T>. It would be nice if Specification<T> interface could be used to create Predicate objects for subqueries too. Right now I have to duplicate the code written in my own Specification classes if I would like to use it for subquery predicates.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions