java - JPA Criteria Query Builder: Get last Entry -
i building complex query jpa criteriabuilder.
in query join little databases. need last entry of joined table. don't know must applicate in query.
here dummy jpa query:
private criteriaquery<class2> getclass2function { criteriaquery<rootclass> cq = cb.createquery(rootclass.class); root<rootclass> root = cq.from(rootclass.class); join<rootclass, class2> class2 = root.join(rootclass_.class2id); listjoin<class2, class3> class3 = class2.join(class2_.listofclass3); list<predicate> predicates = new arraylist<>(); predicates.add(cb.isnull(class3.get(somemodel_.dtdl))); predicates.add(cb.isnull(class2.get(somemodel_.dtdl))); predicates.add(cb.isnull(root.get(somemodel_.dtdl))); return cq.select(class2).where(predicates.toarray(new predicate[] {})) .orderby(cb.asc(class2.get(class2_.id))); }
now need last entry of listjoin class3
, how can this?
greetings
i have found solution.
needed add following code:
subquery<long> sq = cq.subquery(long.class); root<class3> root = sq.from(class3.class); sq.select(cb.max(root.get(class3_.id))); predicates.add(cb.equal(class3.get(class3_.id), sq));
i hope someone.
Comments
Post a Comment