IIRC, a join
(fetch
) to Image
in that query would solve such problem.
Now, as you need to specify the Image
class, I'll show you a non-generic solution, so you can verify if it works.
// notice I changed all <T> to <App>
public List<App> findByPage(int pageNum, int pageSize) {
CriteriaQuery<App> cq = getEntityManager()
.getCriteriaBuilder().createQuery(entity);
Root<App> root = query.from(App.class); // added this
root.fetch("app"); // added this, this is the join
cq.select(cq.from(entity));
int firstResult = pageNum * pageSize;
return getEntityManager().createQuery(cq)
.setFirstResult(firstResult)
.setMaxResults(pageSize)
.getResultList();
}
I'm not 100% on this (I have't tested, and don't know if the "app"
string is the right way -- it should be the field which you want to "pull", but as this is many to one, I'm unsure, and placed the field in Image
that refers to App
instead), but I think the solution is somewhere around a join
and hopefully this points in the right direction.