jpql从一个表中选择列,并从另一个表中排序,而不使用本机查询

时间:2017-10-10 02:25:40

标签: java hibernate jpa

您好我想从另一个表的列中排序时从一个表中选择列。效果应与此SQL相同:

SELECT DISTINCT m.marker_name FROM Marker m INNER JOIN Lease l ON m.marker_name = l.marker_name ORDER BY l.location

表格标记

╔═════════════╗
║ marker_name ║
╠═════════════╣
║ ABC         ║
╟─────────────╢
║ DEF         ║
╚═════════════╝

表租约:

╔══════════╤═════════════╗
║ location │ marker_name ║
╠══════════╪═════════════╣
║ 01-01    │ ABC         ║
╟──────────┼─────────────╢
║ 01-02    │ DEF         ║
╟──────────┼─────────────╢
║ 01-01    │ GHI         ║
╟──────────┼─────────────╢
║ 01-02    │ JKL         ║
╚══════════╧═════════════╝

我尝试使用以下JPA / Hibernate SQL但失败了:

@Query("SELECT DISTINCT m.markerName FROM Marker m INNER JOIN Lease l ON m.marker_name = l.marker_name ORDER BY l.location")
List<String> findDistinctMarkernameOrderByLocation();

错误:

Path expected for join! [SELECT DISTINCT l.markerName FROM Lease l INNER JOIN Marker m ON m.marker_name = l.marker_name ORDER BY l.location]

我试图避免使用本机查询,所以只是想知道是否有任何JPQL工作。

0 个答案:

没有答案