[英]HQL Join with three tables
I'm having some issues with HQL since I'm a newbie with it.我对 HQL 有一些问题,因为我是它的新手。 Even though I don't have issues with "simple queries", I am currently stuck with a query involving three tables.
尽管我对“简单查询”没有任何问题,但我目前仍坚持使用涉及三个表的查询。
I have already gone through some tutorials, but I haven't been able to find a valid example for my needs.我已经阅读了一些教程,但是我无法找到满足我需求的有效示例。 I have tried my best to explain my problem:
我已尽力解释我的问题:
I have three different tables, let's name them HOUSES
, OWNERS
, and OWNERINFOS
.我有三个不同的表,让我们的名字他们
HOUSES
, OWNERS
和OWNERINFOS
。
Given a townId
, I need to list all houses from that town, including name
and surname
of that house-owner.给定一个
townId
,我需要从那个小镇,包括列出所有的房子name
和surname
的是房主的。
I made a really simple graph to show the connections between tables:我制作了一个非常简单的图表来显示表格之间的联系:
I'm also not sure which join-strategy I should use.我也不确定我应该使用哪种连接策略。 Any kind of help would be highly appreciated, since solving this is a priority for me.
任何形式的帮助都将受到高度赞赏,因为解决这个问题对我来说是一个优先事项。
Thanks in advance!提前致谢!
It is just a template它只是一个模板
class House {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_town")
private Town town;
@OneToMany(mappedBy = "house")
private List<Owner> owners;
}
class Owner {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_house")
private House house;
@OneToOne
@JoinColumn(name = "fk_owner_info")
private OwnerInfo ownerInfo;
}
class OwnerInfo {
@OneToOne(mappedBy = "ownerInfo", fetch = FetchType.LAZY)
private Owner owner;
}
The simplest case with fetch all owners with owner info使用所有者信息获取所有所有者的最简单情况
from House h inner join fetch h.owners where h.town.id = :townId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.