2013-02-26 171 views
0

我都已經設定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值呈先的實體,稱爲ServiceList .. 當我做我的Hibernate查詢我喜歡這...

{ 
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 ......我該怎麼做.. .. 有什麼建議麼 ?

回答

0

論的createQuery方法返回的Query對象的entityManager可以使用方法setMaxResult,並連同訂單在您的查詢中使用此。