/** * @see DATAJPA-403 */ @Test public void reusesExistingJoinForExpression() { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<User> query = builder.createQuery(User.class); Root<User> from = query.from(User.class); PropertyPath managerFirstname = PropertyPath.from("manager.firstname", User.class); PropertyPath managerLastname = PropertyPath.from("manager.lastname", User.class); QueryUtils.toExpressionRecursively(from, managerLastname); QueryUtils.toExpressionRecursively(from, managerFirstname); assertThat(from.getJoins(), hasSize(1)); }
/** * @see DATAJPA-401 */ @Test public void doesNotCreateAJoinForNonOptionalAssociation() { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Order> query = builder.createQuery(Order.class); Root<Order> root = query.from(Order.class); QueryUtils.toExpressionRecursively(root, PropertyPath.from("customer", Order.class)); }
/** * @see DATAJPA-454 */ @Test public void createsJoingToTraverseCollectionPath() { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<User> query = builder.createQuery(User.class); Root<User> root = query.from(User.class); QueryUtils.toExpressionRecursively(root, PropertyPath.from("colleaguesLastname", User.class)); assertThat(root.getJoins(), hasSize(1)); }
/** * @see DATAJPA-401 */ @Test public void createsJoinForOptionalAssociation() { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<User> query = builder.createQuery(User.class); Root<User> root = query.from(User.class); QueryUtils.toExpressionRecursively(root, PropertyPath.from("manager", User.class)); assertThat(root.getJoins(), hasSize(1)); }