我尝试并阅读了有关此问题的其他问题,但我无法将逻辑应用于我的案例。 我想从这张表中选择:
@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!
有人可以解释一下如何解决这个问题吗? 最好的问候
答案 0 :(得分: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