2012-05-16 19 views

回答

2

分析

看着Hibernate的CriteriaQuery parent's QueryStructure from(..)方法:

public <X> Root<X> from(Class<X> entityClass) { 
    EntityType<X> entityType = criteriaBuilder.getEntityManagerFactory() 
      .getMetamodel() 
      .entity(entityClass); 
    if (entityType == null) { 
     throw new IllegalArgumentException(entityClass + " is not an entity"); 
    } 
    return from(entityType); 
} 

public <X> Root<X> from(EntityType<X> entityType) { 
    RootImpl<X> root = new RootImpl<X>(criteriaBuilder, entityType); 
    roots.add(root); 
    return root; 
} 

我們看到,其中一個只是一個超載。

結果

更方便和鍋爐板逃逸方式將被傳遞類作爲參數。

諮詢

您沒有提供您正在使用的JPA實現,因爲JPA的CriteriaQuery中只是一個接口,而實現供應商如的EclipseLink或休眠提供實際的實現。下一次,如果考慮到這一點,這將是非常重要的。

+0

我使用Hibernate作爲實現。感謝您的回答 :) – lrxw

相關問題