Criteria queries allow for multiple root level objects. Caution should be used when doing this, as it can result in Cartesian products of the two table. The where clause should ensure the two objects are joined in some way.
// Select the employees and the mailing addresses that have the same address.
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
Root employee = criteriaQuery.from(Employee.class);
Root address = criteriaQuery.from(MailingAddress.class);
criteriaQuery.multiselect(employee, address);
criteriaQuery.where(criteriaBuilder.equal(employee.get("address"), address.get("address"));
Query query = entityManager.createQuery(criteriaQuery);
List<Object[]> result = query.getResultList();
The Visual Query Builder helps you construct complex database queries without you having to know the syntax of SQL statements. A rich set of visual options are available to let you combine SQL clauses like JOINs, GROUP BY with properties like Indexes, Operators, Aliases, Sort Type, Sort Order and Criteria. Based on your selections, the Visual Query Builder will generate a complete SQL statement that can be executed. Features like Quick Criteria Mode, Quick Filtering, Index Assistant, flexible layouts, and drag and drop to include JOINs save you time and make the process of building queries more powerful and intuitive.