限制 Hibernate Criteria 查询中关联的类
我有一个对象“Response”,它有一个名为“submitter”的属性。提交者可以是几个不同类别之一,包括学生、教师等...
我希望能够执行条件查询,其中我仅选择教师提交的响应 - 因此这意味着对关联实体施加类别限制。对此有什么想法吗?我想远离直接 SQL 或 HQL。
I have an object, 'Response' that has a property called 'submitter'. Submitters can be one of several different classes including Student, Teacher, etc...
I would like to be able to execute a criteria query where I select only responses submitted by teachers - so this means putting a class restriction on an associated entity. Any ideas on this? I'd like to stay away from direct SQL or HQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Gavin King 的说法,以下内容适用于 HQL:
您尝试过吗
?
According to Gavin King, the following works with HQL:
Have you tried
?
我最终使用了原生 SQL。不是最好的,但也并不可怕:
值得注意的是,这仅在我使用每个继承层次结构表映射策略时才有效。没有它,我就不会有鉴别器专栏。
I ended up using native SQL. Not the greatest, but it isn't horrible either:
It's worth noting that this only worked because I was using the table-per-inheritance-hierarchy mapping strategy. Without that, I wouldn't have had a discriminator column.