JPA Criteria query Path.get left join is it possible

后端 未结 1 751
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 query = criteriaBuilder.createQuery(InventoryItemSumReport.class);
     Root from = query.from(InventoryItemDetail.class);    
    
     Join joinItem = from.join(InventoryItemDetail_.inventoryItem); 
    
     Predicate where = criteriaBuilder.lessThanOrEqualTo(from.get(InventoryItemDetail_.effectiveDate), date);
    
     Join 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 createQuery = getEm().createQuery(query);       
     List resultList = createQuery.getResultList();
    

    0 讨论(0)
提交回复
热议问题