2016-07-26 39 views
0

當我在這兩個表之間寫入連接查詢時,我在兩個表之間有manyToMany關係,加載項目時出現錯誤。manytoMany join查詢中的「org.hibernate.HibernateException:命名查詢中的錯誤」

下面是該查詢:

@NamedQueries ({ 
@NamedQuery(name = "LicenseComponentDefinition.findByProductVerKeyType", query = "SELECT c from LicenseComponentDefinition c join c.licenseKeyTypes lkt WHERE lkt.keyTypeId = :keyTypeId AND WHERE c.product.productId = :productID AND c.productVersionByVersionStartId.versionId <= :versionId AND c.productVersionByVersionEndId.versionId >= :versionId") 

})

與實體類看起來像下面

private Set<LicenseKeyType> licenseKeyTypes = new HashSet<LicenseKeyType>(0); 
@ManyToMany(fetch = FetchType.LAZY) 
@JoinTable(name = "component_definition_keytypes", catalog = "ldbredesigned", joinColumns = { 
     @JoinColumn(name = "component_definition_id", nullable = false, updatable = false) }, inverseJoinColumns = { 
       @JoinColumn(name = "license_key_type_id", nullable = false, updatable = false) }) 
public Set<LicenseKeyType> getLicenseKeyTypes() { 
    return this.licenseKeyTypes; 
} 

它工作正常,當我從查詢中刪除聯接子句。像下面一樣

SELECT c from LicenseComponentDefinition c WHERE c.product.productId = :productID AND c.productVersionByVersionStartId.versionId <= :versionId AND c.productVersionByVersionEndId.versionId >= :versionId 

有人可以幫忙嗎? 謝謝。

回答

0

您的指定查詢有2凡在它的關鍵字:

SELECT c 
from LicenseComponentDefinition c join c.licenseKeyTypes lkt 
WHERE lkt.keyTypeId = :keyTypeId 
AND WHERE c.product.productId = :productID 
AND c.productVersionByVersionStartId.versionId <= :versionId 
AND c.productVersionByVersionEndId.versionId >= :versionId") 

拍攝:第二個對於初學者。