The title says it all: is it possible to use a named query inside of a query built with the JPA criteria API ? Something along the lines of (simple example):
@Entity
@NamedQuery(name = "complexFooQuery", query = "FROM Foo where ....")
class Foo {
////....
}
List<Foo> getFoo() {
CriteriaQuery<Foo> cq = em.createQuery(Foo.class);
cq.select(<somehow specify complex foo named query>);
return em.createQuery(cq).getResultList();
}
No. Criteria queries are constructed dynamically (so to give typesafe handling) ... and if just dumping some named query in then there would be no typesafe handling. Besides, a subquery is illegal in the SELECT clause for strict JPQL (and a JPQL query starts with "SELECT {alias}" too FWIW)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.