查询实体实例与 GORM 的 M:N 关系_不_相互关联?
我需要跟踪与属性的 M:N 关系,因此我使用链接表(遵循 没有 Hibernate XML 的多对多映射) ...但是,我不知道如何查询该会员资格合法但尚不存在的关系,例如,不在给定团队中的任何员工(或用户尚未出价的项目等)。我正在 HQL 中研究它,但我对此很菜鸟,所以我可以使用一些关于什么技术最有效的指导......或者,此类查询的示例;)
为了讨论,只需假设员工:团队会员级别,每个级别都有一个非常大的集合(太大而无法直接拉入中间层并进行集合操作)。
class Membership {
Employee employee
Team team
String other // I need attributes on the relationship
}
class Employee {
Date dateJoinedCompany
String name
static hasMany = [managedTeams:Team, memberships:Membership]
static mappedBy = [managedTeams:"manager"]
}
class Team {
String name
Employee manager
static belongsTo = Employee
static hasMany = [memberships:Membership]
}
因此,我需要一个查询,该查询返回一个多月前不属于团队 #2 的员工,或者员工 #5 不属于的团队,诸如此类的事情什么是最好的技术 - 有没有办法做这与标准?或者,关于如何最好地使用 HQL 有什么建议吗?
我应该添加我当前的想法,使用 HQL 和子选择:
from Team t where t not in (select m.team from Membership m where m.employee = 5)
TIA!
I need to track a M:N relationship with attributes, so I'm using a link table (following the pattern at Many-to-Many Mapping without Hibernate XML) ... but, I can't see how to query that Membership relationship for legal-but-don't-yet-exist relationships, e.g., any Employees not in a given Team (or Items which a User hasn't yet bid on, etc). I'm working on it in HQL, but I'm a noob to that so I could use some guidance on what technique works best ... or, examples of this sort of query ;)
For discussion, just assume the Employees:Team Membership class, with a very large set of each (too large to just pull into the mid-tier and do set operations).
class Membership {
Employee employee
Team team
String other // I need attributes on the relationship
}
class Employee {
Date dateJoinedCompany
String name
static hasMany = [managedTeams:Team, memberships:Membership]
static mappedBy = [managedTeams:"manager"]
}
class Team {
String name
Employee manager
static belongsTo = Employee
static hasMany = [memberships:Membership]
}
So, I need a query which returns Employees not on Team #2 who jined the company more than a month ago, or Teams which Employee #5 is not part of, that sort of thing What's the best technique - is there a way to do this with Criteria? Or, any suggestions on how to best use HQL for it?
I should add my current thought, using HQL and a subselect:
from Team t where t not in (select m.team from Membership m where m.employee = 5)
TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个多月前不属于团队 #2 的员工:
员工 #5 不属于的团队
Employees not on Team #2 who jined the company more than a month ago:
Teams which Employee #5 is not part of