0

我有一个名为 ServiceList 的实体,它有一组 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;
}

诀窍是在 internalOrder 中,最高的 internalOder 值首先显示..当我进行休眠查询时,我确实喜欢这样...

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

我的问题是:-我想对左连接设置一个限制,这意味着当我进行查询时我只想获得最高的 10 个 productSeriveListOrders ...我该怎么做...有什么建议吗?

4

1 回答 1

0

在您的方法Query返回的对象上,您可以使用该方法并将其与查询中的 order by 结合使用。createQueryentityManagersetMaxResult

于 2013-02-26T18:45:36.417 回答