I have a "vanilla" JPA specification prepared for certain entity. I also have Blase-persistence entity view interface prepared for the same entity. How can I load that entity view using prepared JPA specification?
Edit: Currently, I'm using this specification like so:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<EntityClass> query = cb.createQuery(EntityClass.class);
Root<EntityClass> root = query.from(EntityClass.class);
query.where(specification.toPredicate(root, query, cb));
EntityGraph graph = entityManager.getEntityGraph(entityGraphName);
TypedQuery<EntityClass> = entityManager.createQuery(query)
.setHint("javax.persistence.loadgraph", graph);
List<EntityClass> result = typedQuery.getResultList();
After that, I'm converting list of entities into list of projections. Right now, I'm trying to replace both entity graphs and projections with entity views in similar scenario, with class for entity view coming as parameter.
You can convert the
CriteriaQuery, or actuallyBlazeCriteriaQuery, to a Blaze-PersistenceCriteriaBuilderas outlined in the quickstart which would look roughly like this:At this point, you can apply a
EntityViewSettingonto that query and retrieve the results as outlined in the entity-view quickstart: