Hibernate:标准中多对一的投影
我最近第一次使用 hibernate Criteria API。
我试图做相当于此 HQL
“从任务 t 选择 t.userTbl”
userTbl 属性是来自任务的多对一。 Task.userTbl 关系是惰性的。
所以我想出了这个,
Criteria criteria = session.createCriteria( Task.class, "t" );
criteria.setProjection( Projections.property( "t.userTbl" ) );
List results = criteria.list();
不幸的是,这与 HQL 做了一些不同的事情。
在 HQL 中,尽管 userTbl 关系在映射中设置为惰性,但 HQL 会急切地获取并具体化 UserTbl 的非代理对象。
然而,在标准中,我得到了我不想要的代理列表。我摆弄了 setFetchMode 但这似乎不是正确的事情。任何人都知道如何在标准中正确执行上述操作并像 HQL 一样恢复非代理?
谢谢。
I am playing around with the hibernate Criteria API for the first time recently.
I was trying to do the equivalent of this HQL
"select t.userTbl from Task t"
userTbl property is a many-to-one from Task. The Task.userTbl relationship is lazy.
So I came up with this
Criteria criteria = session.createCriteria( Task.class, "t" );
criteria.setProjection( Projections.property( "t.userTbl" ) );
List results = criteria.list();
Unfortunately this does something different to HQL.
In HQL although the userTbl relationship is set to lazy in the mapping the HQL eagerly fetches and materialises non-proxy objects of UserTbl.
However in the Criteria I get a list of proxies back which I don't want. I fiddled around with setFetchMode but this didn't seem to be the right thing. Anyone have any idea how to do the above in a Criteria properly and get non-proxies back like HQL?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试强制任务类和 userTbl 之间的连接。
Try to force a join between the task class and the userTbl.