0

Is there any way I can get a JPASubQuery from a JPAQueryand vice versa? I have a JPAQuery and I want to reuse it as a subquery but seems like there's not any kind of common interface between the two so that I can perform this transition. The query is quite big and it gets anything but nice rewriting the entire thing as a sub query (actually duplicating the identical from part). So I am looking for something like this:

JPAQuery query = new JPAQuery(entityManager);
query.from(e).leftJoin(and(or(c1,c2,c3),c4,c5)).where(and(c6,c7,c8));
JPASubQuery sub = query.toSubQuery();
Niko
  • 616
  • 4
  • 20

1 Answers1

0

You can transform a JPAQuery to a JPASubQuery like this:

new JPASubQuery(query.getMetadata().clone());

Solution found here.

Niko
  • 616
  • 4
  • 20