2017-06-27 87 views
1

我試過並閱讀了有關此問題的其他問題,但我無法將邏輯應用於我的案例。 我試圖從該表中選擇:HQL錯誤 - 預計加入的路徑

@Entity 
public class LabelStatistics { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private int ID; 

    @Enumerated(EnumType.STRING) 
    private AnalysisType type; 

    private String labelId; 
    private String hexLabelId; 
    private Timestamp timestamp; 

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) 
    private List<LabelStatisticsItem> results; 

我試圖執行以下語句:

@Query(value = "SELECT s1.labelId, s1.type, s1.timestamp " 
     + "FROM LabelStatistics s1 " 
     + "INNER JOIN LabelStatistics s2 on s1.labelId = s2.labelId and s1.type = s2.type and s1.timestamp < s2.timestamp") 
List<Object[]> findLatestStatisticsEntries(); 

我不斷收到此錯誤:

org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! 

有人能解釋的請問如何解決這個問題? 此致敬禮

回答

5

我想這是因爲只有在設置關係的實體之間允許連接。

嘗試使用WHERE代替

SELECT s1.labelId, s1.type, s1.timestamp 
FROM LabelStatistics s1, LabelStatistics s2 
WHERE s1.labelId = s2.labelId and s1.type = s2.type and s1.timestamp < s2.timestamp 
相關問題