【发布时间】:2017-02-28 11:41:48
【问题描述】:
我有 2 个表:Claim 和 Type_Claim。 Claim 在 Type_Claim 上有一个外部键。在 Hibernate 中,表示 Claim 表的 Bean 具有 TypeClaim 作为属性。
Claim
ID TYPE
1 2
2 2
3 4
4 1
Type_Claim
ID Description
1 "Hello"
2 "Hi"
3 "House"
4 "Welcome"
5 "Bye"
现在我做了这个查询:
SELECT tc.description, COUNT(*)
FROM Claim claim"
LEFT OUTER JOIN claim.typeClaim tc
GROUP BY tc.description ";
我想得到这个:
Description Count
"Hello" 1
"Hi" 2
"House" 0
"Welcome" 1
"Bye" 0
但我得到了这个:
Description Count
"Hello" 1
"Hi" 2
"Welcome" 1
如何在查询中包含 0 结果?我尝试使用 RIGHT JOIN,但得到了相同的结果。
【问题讨论】:
-
应该使用右连接。可以贴一下生成的 SQL 吗?
标签: java mysql sql hibernate hql