Grails GORM具有多对多属性

Grails GORM具有多对多属性,grails,gorm,Grails,Gorm,我有两个域类: class A { int id static hasMany = [bs: B] } class B { int id } 我可以使用GORM查找与具有给定id的B实例相关的所有A实例吗? 我试过: 但我得到了以下错误: Class: java.sql.SQLException Message: No value specified for parameter 1 来自Gorm文档 查询关联 可以通过具有与属性名称匹配的节点来查询关联。例如,假设A

我有两个域类:

class A {
    int id
    static hasMany = [bs: B]
}

class B {
    int id
}
我可以使用GORM查找与具有给定id的B实例相关的所有A实例吗?
我试过:

但我得到了以下错误:

Class: java.sql.SQLException
Message: No value specified for parameter 1

来自Gorm文档

查询关联

可以通过具有与属性名称匹配的节点来查询关联。例如,假设Account类有许多事务对象:

class Account {
   …
   static hasMany = [transactions: Transaction]
   …
}
我们可以使用属性名称事务作为生成器节点来查询此关联:

def c = Account.createCriteria()
def now = new Date()
def results = c.list {
    transactions {
        between('date', now - 10, now)
    }
}
上述代码将查找在过去10天内执行过交易的所有帐户实例。您还可以在逻辑块中嵌套此类关联查询:

def c = Account.createCriteria()
def now = new Date()
def results = c.list {
    or {
        between('created', now - 10, now)
        transactions {
            between('date', now - 10, now)
        }
    }
}
所以这应该有效:

def c = A.createCriteria()
def results = c.list {
    bs {
        // Conditions...
    }
}
希望它能帮助你,或者给你一些提示

def c = A.createCriteria()
def results = c.list {
    bs {
        // Conditions...
    }
}