假设我有2个mysql表:
create table tableA (
id bigint not null auto_increment,
name varchar(255),
primary key (id)
);
create table tableB (
id bigint not null auto_increment,
title varchar(255),
big_data longtext,
tableA_id bigint,
primary key (id)
);
相应的hibernate实体:
public class A {
private String name;
private List<B> list;
}
public class B {
private String title;
private String data;
private A a;
}
我有以下SQL:
select a.id, count(b.id)
from tableA as a left outer join
(select id, title, tableA_id from tableB) as b on a.id = b.tableA_id
group by a.id;
如何将其转换为HQL?
请不要优化查询!我想要使用HQL来生成这个SQL。 即使它不是最佳的。