skylla
skylla

Reputation: 464

HQL Error - Path expected for join

I tried and read other questions regarding this problem, but I could not apply the logic to my case. I am trying to select from this table:

@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;

I am trying to execute the following statement:

@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();

I keep getting this error:

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

Could someone explain on how to solve this please? Best regards

Upvotes: 1

Views: 7792

Answers (1)

StanislavL
StanislavL

Reputation: 57421

I guess it happens because joins are allowed only between entities where relations are set.

Try to use WHERE instead

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

Upvotes: 7

Related Questions