JPA Criteria query Path.get left join is it possible

后端 未结 1 747
Happy的楠姐
Happy的楠姐 2021-02-14 20:03

I have a question regarding JPA criteria.

Here is my JPA criteria query:

 CriteriaBuilder criteriaBuilder = getEm().getCriteriaBuilder();
 CriteriaQuery&         


        
相关标签:
1条回答
  • 2021-02-14 20:32

    I found as follows it works:

     CriteriaBuilder criteriaBuilder = getEm().getCriteriaBuilder();
     CriteriaQuery<InventoryItemSumReport> query = criteriaBuilder.createQuery(InventoryItemSumReport.class);
     Root<InventoryItemDetail> from = query.from(InventoryItemDetail.class);    
    
     Join<InventoryItemDetail, InventoryItem> joinItem = from.join(InventoryItemDetail_.inventoryItem); 
    
     Predicate where = criteriaBuilder.lessThanOrEqualTo(from.get(InventoryItemDetail_.effectiveDate), date);
    
     Join<InventoryItem, Customer> joinCustomer = joinItem.join(InventoryItem_.customer, JoinType.LEFT);
     query.multiselect(joinItem.get(InventoryItem_.product),joinItem.get(InventoryItem_.facility),joinItem.get(InventoryItem_.customer));
     query.groupBy(joinItem.get(InventoryItem_.product),joinItem.get(InventoryItem_.facility),joinCustomer);
     query.where(where); 
    
     TypedQuery<InventoryItemSumReport> createQuery = getEm().createQuery(query);       
     List<InventoryItemSumReport> resultList = createQuery.getResultList();
    
    0 讨论(0)
提交回复
热议问题