0

I have an entity called ServiceList that has set of productListOrders

 @Entity
 @Table(name="service_lists")
 public class ServiceList implements Serializable {
private static final long serialVersionUID = 1L;
    private Set<ProductServiceListOrder> productServiceListOrders = new HashSet<ProductServiceListOrder>();
}

ProductServiceListOrder looks like this 
public class ProductServiceListOrder implements Serializable {
private static final long serialVersionUID = 1L;

private ServiceList serviceList;
private Product product;
private Date createdAt;

private Long id;
private Integer internalOrder;
}

The trick is in internalOrder which the highest internalOder value showed first .. when I do my hibernate query I do like this ...

{
List<ServiceList> lists = (List<ServiceList>) JPA.em().createQuery(
                    "select  distinct list from com.vionlabs.movieoncloud.model.main.ServiceList list " +
                            "left join fetch list.productServiceListOrders "  )
}

MY QUESTION IS :- I want to set a limit on left join that means I want to get only the highest 10 productSeriveListOrders when I do the query ... How I can do this .... any suggestions ?

Code Lღver
  • 15,573
  • 16
  • 56
  • 75

1 Answers1

0

On the Query object returned by the createQuery method of your entityManager you can use the method setMaxResult and use this in conjunction with an order by on your query.

benzonico
  • 10,635
  • 5
  • 42
  • 50