hibernate hql join hashset问题
我有三个表
users、survey、surveyreponses
我使用 hibernettool 生成
survey 对象中的对象/映射/xml 等,有一组 surveyresponses
private Set Surveyresponses = 新的哈希集(0); <-- 这是调查类中生成的代码
我正在运行查询,
select u.id, s from users u, survey s
where u.id = s.id
但我的调查响应“集”为空。 如何将所有这些调查回复添加到调查集中? 假设我从 Surveyresponses 中引用了调查 id,
这对 Hibernate 来说有点陌生 =) 谢谢
I have three tables
users, survey, surveyreponses
I used hibernettool to generate the objects/mapping/xml etc
in the survey object there is a "set" of surveyresponses
private Set surveyresponses= new HashSet(0); <-- this is generated code inside survey class
I am running the query
select u.id, s from users u, survey s
where u.id = s.id
but my surveyresponses "set" is empty.
How do I add all those surveyresponses into the set in survey?
assuming I have the reference to survey id from surveyresponses
kinda new to hibernate =)
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为当您执行 HQL 时,您将获得一个列表,其中包含查询中的对象,但它不会填充对象中的属性。您需要做的是在调查配置中指定一组调查响应,如下所示:
现在,每当加载调查时,Hibernate 就会填充您的调查集。
Thats because when you are doing HQL you will get a List that has the objects from your query in it, but it won't populate properties in your objects. What you need to do is specify the set of survey responses in your survey's configuration like so:.
Now whenever the survey is loaded Hibernate will populate your set.