HQL:子查询的左外连接
假设我有 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。 即使它不是最佳的。
Let's assume I have 2 mysql tables:
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)
);
And corresponding hibernate entities:
public class A {
private String name;
private List<B> list;
}
public class B {
private String title;
private String data;
private A a;
}
I have the following 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;
How can i convert it to HQL?
PLEASE DO NOT OPTIMIZE QUERY! I'd like to have HQL which will produce exactly this SQL.
Even if it is not optimal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论