HQL:子查询的左外连接

发布于 2024-10-07 05:09:41 字数 806 浏览 12 评论 0原文

假设我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文