hibernate结果集和映射混乱

发布于 2024-09-29 21:49:18 字数 669 浏览 10 评论 0原文


我在通过休眠获得结果时遇到问题。
我有四个表 SnsUser、Participant、Interaction、Content; Sns用户&交互具有多对多关系,交互和内容具有多对一关系。 (SnsUser 和 Interation 在映射类中获得了参与者集,hibernate 则为许多-2-许多)

当我像

from SnsUser s join fetch s.participants p join fetch p.interaction i join fetch i.content c where s.blessUid=1

(返回 List(SnsUser) 列表)

一样运行 HQL 时,它给了我 10 行,每行(即 SnsUser)有 10 行作为参与者。

但是当我像 HQL 一样运行时,

from Participant p join fetch p.snsUser s join fetch p.interaction i join fetch i.content c where s.blessUid=1

它会给我 10 行,我可以从中获取相关的 SnsUser。但 当我查看实际的 sql 查询时,两者都是相同的。为什么它会表现得像这样......?

答案将不胜感激。 阿尔

I was having a problem in getting result through hibernate.
I have four tables SnsUser, Participant, Interaction, Content;
SnsUser & Interaction has many-2-many relationship and Interaction and Content has many-2-one.
(SnsUser and Interation got Set of Participant in there mapping classes, hibernate does for many-2-many)

when I run HQL like

from SnsUser s join fetch s.participants p join fetch p.interaction i join fetch i.content c where s.blessUid=1

(returning List(SnsUser) list)

it gives me let say 10 rows and in each row (i.e. SnsUser) has 10 rows as Participant.

But when i run like a HQL like

from Participant p join fetch p.snsUser s join fetch p.interaction i join fetch i.content c where s.blessUid=1

it gives me 10 rows and i can get the relevant SnsUser from it. BUT
when i look at the actual sql query it is same for the both. Why it behaves like this... ?

answers would be appreciated.
al

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声无音无过去 2024-10-06 21:49:18

我持怀疑态度,两个查询不应该相同(一个查询应该针对 SnsUser 表执行,另一个查询应该针对 Participant 表执行)。

因为我只相信我所看到的,所以在您显示生成的查询(以及允许完全理解模型的映射)之前我不会改变主意。

I'm skeptic, both queries shouldn't be the same (one should be performed against the SnsUser table and the other should be performed against the Participant table).

And because I only trust what I see, I won't change my mind until you show the generated queries (and the mapping allowing to fully understand the model).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文