Grails 多对多 - 动态查找器的问题
我希望你们能帮助我。不幸的是,Google 没有帮助我,我在 stackoverflow 上的搜索也没有帮助:-(
我有两个 DomainClass HumanResource 和 Task ,具有多对多关系
模型定义:
任务:
class Tasks {
String name
static belongsTo = [HumanResource]
static hasMany = [humanResources: HumanResource]
//also tried but didn't help -> static fetchMode = [humanResources:"eager"]
}
HumanResource:
class HumanResource {
String name
static hasMany = [tasks: Tasks]
}
我还尝试使用mapping={}在id字段上添加索引,但我也认为这不是解决方案,它没有帮助,我认为 id 字段上已经有一个索引,
所以,我现在所做的和没有做的是找到给定任务的所有人力资源,并且任务来自服务并且它们已经被获取。带有“static fetchMode = [tasks:"eager"]”的服务模型
:
def listHumanResourcesFromTasks = {
def list = HumanResource.findAllByTasks(service.getTasks())
//and I tried also with an own HashMap but didn't work as well
}
我总是收到错误“org.springframework.dao.InvalidDataAccessResourceUsageException” SQL-GrammarException。但我真的不知道为什么“service.getTasks()”对象已完全填充(正如我用 fetchMode = [tasks:"eager"] 编写的那样)...
如果有人可以的话那就太棒了。给我获胜的提示。
非常感谢您抽出时间。
最美好的祝愿,
马可
I hope you can help me guys. Google unfortunately didn't helps me out and my search here at stackoverflow didn't as well :-(
I have two DomainClasses HumanResource and Task with a many-to-many relationship.
Model-Definitions:
Task:
class Tasks {
String name
static belongsTo = [HumanResource]
static hasMany = [humanResources: HumanResource]
//also tried but didn't help -> static fetchMode = [humanResources:"eager"]
}
HumanResource:
class HumanResource {
String name
static hasMany = [tasks: Tasks]
}
I also tried to add an index on the id-field with mapping={} but I also think that's not the solution, it didn't help and I think there is already an index on the id-field.
So, what I did and not works is now to find all human resources for the given tasks! And the tasks comes from Services and they are already fetched in the service model with "static fetchMode = [tasks:"eager"]"!
Controller-Code:
def listHumanResourcesFromTasks = {
def list = HumanResource.findAllByTasks(service.getTasks())
//and I tried also with an own HashMap but didn't work as well
}
I always get an error "org.springframework.dao.InvalidDataAccessResourceUsageException" with an SQL-GrammarException. But I really don't know why. The "service.getTasks()" objects are fully filled (as I wrote with fetchMode = [tasks:"eager"])...
It would be awesome if somebody could give me the winning hint.
Thanks a lot for your time.
Best wishes,
Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不支持此类查询 - 通常您需要使用 HQL 或条件查询。但这个特殊的关系很容易,因为你们有双向关系。您可以通过以下方式获取
Tasks
集合的所有HumanResource
实例:它需要是一个
Set
,因为相同的HumanResource
实例可能会出现多次,因此您需要将列表压缩为唯一的实例。This sort of query isn't supported - you'd need to use HQL or a criteria query in general. But this particular one is easy since you have a bidirectional relationship. You can get all of the
HumanResource
instances for a collection ofTasks
with this:It needs to be a
Set
since the sameHumanResource
instance may appear multiple times so you need to condense the List into unique instances.