JPA predicate with Querydsl

73 views
Skip to first unread message

Aurélien Baudet

unread,
Apr 13, 2016, 2:26:48 PM4/13/16
to Querydsl
Hello,

I use Querydsl in my application to greatly improve code for querying database.
However, I have a JPA Predicate (javax.persistence.criteria.Predicate) that comes from an external service.
I want to mix my query created with Querydsl and the external predicate. For example:


// JPA Predicate from external service
Root<User> root = ...;
CriteriaBuilder cb = ...;
javax.persistence.criteria.Predicate externalPredicate = externalService.filterEmail(root, cb, "%@gmail.com");

// Create Querydsl predicate
BooleanExpression querydslExp = QUser.username.eq("foo");

// Mix predicates (this is what I need)
querydslExp
.and(externalPredicate);


Another solution could be converting Querydsl predicate into a JPA one:


cb
.and(querydslExp.toJpaPredicate(), externalPredicate);



Is it possible ?
If yes, how can I achieve this ?
If no, is there another solution to mix predicates (like converting both to SQL strings and create a new query) ?

Thanks

timowest

unread,
Apr 13, 2016, 3:03:27 PM4/13/16
to Querydsl
We don't provide a mapping from Querydsl predicate to JPA predicates or the other direction.

You could try to do the conversion yourself, it might be quite easy, if you cover only a subset of the operations.
Reply all
Reply to author
Forward
0 new messages