I\'m trying to create a criteria to retrieve some objects from 3 tables (Associate, Update and Detail). A Detail has reference to Associate and Update, and an Update has ref
Checkout this test with even more than three tables . Also use static meta model instead of using direct attribute names.
@Test
@Rollback(false)
@Transactional
public void
fetch() {
CriteriaBuilder cb =
entityManager.getCriteriaBuilder();
CriteriaQuery cq =
cb.createQuery(Instructor.class);
Root root =
cq.from(Instructor.class);
root.join(Instructor_.idProof);
root.join(Instructor_.vehicles);
Join insStuJoin =
root.join(Instructor_.students);
insStuJoin.join(Student_.instructors);
Join stuVehcileJoin.
= insStuJoin.join(Student_.vehicles);
Join
vehicleDocumentJoin =
stuVehcileJoin.join(Vehicle_.documents);
DataPrinters.
listDataPrinter.accept.
(queryExecutor.fetchListForCriteriaQuery
(cq.select(root).where
(cb.greaterThan(root.get(Instructor_.id), 2),
cb.in(vehicleDocumentJoin.get
(Document_.name)).value("1")
.value("2").value("3")));
}