1
如何使用條件查詢來應用左連接,我只能在Internet上查找內連接條件。Hibernate criteriaQuery - 左連接
Criteria cr = this.sessionFactory.getCurrentSession().createCriteria(A.class, "a").createAlias("a.division", "division");
List<A> list = cr.list();
除法是一個存在於A類中的實體,這是返回我的內部連接結果。我想申請左連接上劃分實體:
select * from A as a left join divisions as division on division.id = a.id;
表的數據:
id name division_id
1 first name 1
3 sec name 2
6 fourth name 2
5 3rd name NULL
表分割後的數據:
id type
1 F
2 G
內連接:
select * from A as a inner join division where a.division_id = division.id
內加入的結果:
+----+-------------+-------------+----+------+
| id | name | division_id | id | type |
+----+-------------+-------------+----+------+
| 1 | first name | 1 | 1 | F |
| 3 | sec name | 2 | 2 | G |
| 6 | fourth name | 2 | 2 | G |
+----+-------------+-------------+----+------+
左連接查詢:
select * from A as a left join division on division.id = a.division_id;
LEFT JOIN結果:
+----+-------------+-------------+------+------+
| id | name | division_id | id | type |
+----+-------------+-------------+------+------+
| 1 | first name | 1 | 1 | F |
| 3 | sec name | 2 | 2 | G |
| 6 | fourth name | 2 | 2 | G |
| 5 | 3rd name | NULL | NULL | NULL |
+----+-------------+-------------+------+------+
你可以使用'where'條款的加入後,但如果你表現出的分貝結構,一些樣本數據,你想要的結果,你會得到更好的答案。 – davejal