@Override public Response findByReview(final Integer id) { final QResponse response = QResponse.response; JPQLQuery query = jpqlQuery(); query.from(response).where(response.review.id.eq(id)); return query.singleResult(response); }
@Test public void One_To_One() { QEmployee employee = QEmployee.employee; QUser user = QUser.user; JPQLQuery query = query(); query.from(employee); query.innerJoin(employee.user, user); query.list(employee); }
@Test @NoBatooJPA public void Enum_In() { QEmployee employee = QEmployee.employee; JPQLQuery query = query(); query .from(employee) .where(employee.lastName.eq("Smith"), employee.jobFunctions.contains(JobFunction.CODER)); assertEquals(1l, query.count()); }
@Override public ProductReview getById(Long id) { QProductReview qEntity = QProductReview.productReview; QProductReviewDescription qDescription = QProductReviewDescription.productReviewDescription; QProduct qProduct = QProduct.product; JPQLQuery query = new JPAQuery(getEntityManager()); query .from(qEntity) .join(qEntity.customer) .fetch() .join(qEntity.product, qProduct) .fetch() .leftJoin(qProduct.merchantStore) .fetch() .leftJoin(qEntity.descriptions, qDescription) .fetch() .where(qEntity.id.eq(id)); return query.uniqueResult(qEntity); }
@Override public List<ProductReview> getByProduct(Product product) { QProductReview qEntity = QProductReview.productReview; QProductReviewDescription qDescription = QProductReviewDescription.productReviewDescription; QProduct qProduct = QProduct.product; JPQLQuery query = new JPAQuery(getEntityManager()); query .from(qEntity) .join(qEntity.customer) .fetch() .join(qEntity.product, qProduct) .fetch() .leftJoin(qProduct.merchantStore) .fetch() .leftJoin(qEntity.descriptions, qDescription) .fetch() .where(qProduct.id.eq(product.getId())); return query.list(qEntity); }
@Override public ProductPrice getById(Long id) { QProductPrice qEntity = QProductPrice.productPrice; QProductAvailability qAvailability = QProductAvailability.productAvailability; QProductPriceDescription qEntityDescription = QProductPriceDescription.productPriceDescription; QProduct qProduct = QProduct.product; JPQLQuery query = new JPAQuery(getEntityManager()); query .from(qEntity) .innerJoin(qEntity.productAvailability, qAvailability) .fetch() .innerJoin(qAvailability.product, qProduct) .fetch() .leftJoin(qEntity.descriptions, qEntityDescription) .fetch() .innerJoin(qProduct.merchantStore) .fetch() .where(qEntity.id.eq(id)); return query.uniqueResult(qEntity); }