如何将sql转换成jpql查询?

kqqjbcuj  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(354)

我得到了这个sql查询,它返回count
头等舱:

public class Niveau2  implements Serializable{
    @Id
    @GeneratedValue
    private int id2emeniveau;
    private int ok;
    private int next;
    private Date date;

    @ManyToOne
    @JoinColumn(name = "idzebra")
    private Zebra zebra;

二等舱:

public class Zebra implements Serializable {
    @Id
    @GeneratedValue
    private Integer idzebra;
    private String type;
    private int resolution;
    private int reseau;
    private String adresseip;
    private String snum;
    private Date dateaqui;
    private Integer affectter;
    private int etat;
    private String poste, ligne, zone, pole;

    @OneToMany(mappedBy = "zebra")
    private List<Niveau2> niveau2;

sql语句:

SELECT COUNT(ok) FROM mydb.2emeniveau 
INNER JOIN mydb.zebra ON zebra.idzebra=2emeniveau.idzebra 
WHERE 2emeniveau.ok='0' AND zebra.pole='ADT'"

我想把它转换成jpql

oymdgrw7

oymdgrw71#

试试这个:

SELECT COUNT(nv2) FROM Niveau2 nv2 
JOIN nv2.zebras zebras 
WHERE nv2.ok = '0' AND zebras.pole = 'ADT'

相关问题