hibernate结果集和映射混乱
我在通过休眠获得结果时遇到问题。
我有四个表 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我持怀疑态度,两个查询不应该相同(一个查询应该针对
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 theParticipant
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).