Sunny
Sunny

Reputation: 187

JPQL does not have a condition following the "on" keyword

I have a Motif class that is many-to-one with Allele and an Allele class that is many-to-one with Locus.

public class Motif {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

---- another attributes ----

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
    @JoinColumn(name = "allele_id")
    private Allele allele;
}
public class Allele {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

    @Column(name = "allele")
    private Float allele;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
    @JoinColumn(name = "locus_id")
    private Locus locus;

    @OneToMany(mappedBy = "allele", cascade = CascadeType.ALL)
    private List<Motif> motifs;
}
public class Locus {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

    @Column(name = "locus")
    private String locus;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
    @JoinColumn(name = "kit_id")
    private Kit kit;

    @OneToMany(mappedBy = "locus", cascade = CascadeType.ALL)
    private List<Allele> alleles;
}

And I queried with JPQL this query.

SELECT m FROM Motif m JOIN Allele a JOIN Locus l WHERE a.allele = :allele AND l.locus = :locus ORDER BY m.seqNo

It throws some syntax exceptions. So, I enabled the log for displaying SQL. I see this.

    select
        motif0_.id as id1_9_,
        motif0_.allele_id as allele_i5_9_,
        motif0_.pattern as pattern2_9_,
        motif0_.range_seq as range_se3_9_,
        motif0_.seq_no as seq_no4_9_ 
    from
        motif motif0_ 
    inner join
        allele allele1_ 
            on 
    inner join
        loci locus2_ 
            on 
    where
        allele1_.allele=? 
        and locus2_.locus=? 
    order by
        motif0_.seq_no

Why doesn't it have any conditions after the on keyword?

Thank you in advance. I have tried to search for a lot of these issues, but I haven't found any solutions to solve my issue.

Upvotes: 0

Views: 34

Answers (1)

pleft
pleft

Reputation: 7905

The JPQL join query should look like the following:

SELECT m FROM Motif m JOIN m.allele a JOIN m.locus l WHERE a.allele = :allele AND l.locus = :locus ORDER BY m.seqNo

Upvotes: 1

Related Questions