简体   繁体   中英

MySQL to JPA/JPQL query

I try to transform my Mysql query into JPQL, but I don't know which tool can be used on eclipse without compiling.

My logg doesn't tell me where is the error, so I can't find where is the wrong syntax.

This is my query : "SELECT COUNT(*) FROM computer c LEFT JOIN company comp ON c.company_id = comp.id where c.name like ?"

I tried like this : "SELECT COUNT(*) FROM computer c LEFT JOIN company comp ON c.company_id = comp.id where c.name like :filter"

but it doesn't works.

Computer class :

@Entity
@Table(name="computer")
//@NamedQuery(name="computer.rowsWithFilter", query="select count(c.id) from computer c left join company comp on c.company_id = comp.id where c.name like :filter") 
public class Computer {

    @Id @GeneratedValue
    private long id;

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

    @Column(name="introduced")
    private LocalDate introduced;

    @Column(name="discontinued")
    private LocalDate discontinued;

    @ManyToOne
    private Company company;

Company class :

@Entity @Table(name ="company")

public class Company {

    @Id
    @GeneratedValue
    private long id;

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

Thanks for your help !

try this:

SELECT COUNT(c.id) 
FROM computer c 
LEFT JOIN c.company comp
where c.name like :filter

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