简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM