2015-10-16 66 views
0

我有以下實體:JPA - 選擇多對多場

@Entity 
@Data 
@EqualsAndHashCode(callSuper = true) 
@NoArgsConstructor 
@AllArgsConstructor 
public class Seat extends AbstractEntity<Long> { 
    @ManyToOne 
    private Performance performance; 

    @ManyToMany 
    private List<Rate> availableRates; 
} 

我想在JPQL執行以下查詢:

SELECT DISTINCT s.availableRates FROM Seat s WHERE :performance = s.performance 

,但我一直有如下錯誤

無法準備聲明; SQL [select count(distinct。)as col_0_0_ from seat seat0_,seat_available_rates availabler1_,rate rate2_ where seat0_.identifier = availabler1_.seat_identifier and availabler1_.available_rates_identifier = rate2_.identifier and?= seat0_.performance_identifier];嵌套的異常是org.hibernate.exception.SQLGrammarException:無法準備語句

如何編寫正確的查詢?

+0

不能選擇多個值字段,按照JPA規範 –

回答

1

嘗試此查詢:

SELECT DISTINCT r FROM Seat s JOIN s.availableRates r WHERE s.performance = :performance 
+0

這就是它!所以我的問題不是JPQL,而是SQL本身:)讓我們回到我的書,非常感謝 – Maxime