我正在处理我的 grails 项目,并且想要检索具有特定 Activity 类型的所有 CompanyProfileOtherDetails 实例。
def getInstance
getInstance = CompanyProfileOtherDetails.findAll('from CompanyProfileOtherDetails as od where od.activityType in(:activityTypes)', [activityTypes: ActivityType.findAllByName(['Distribution', 'Dealer'])])
我期望 CompanyProfileOtherDetails 实例的输出,但实际输出是
unexpected end of subtree [from ph.gov.doe.core.stakeholder.CompanyProfileOtherDetails as od where od.activityType in()]
这是 CompanyProfileOtherDetails 域类
package ph.gov.doe.core.stakeholder
import ph.gov.doe.core.product.ProductType
import ph.gov.doe.core.requirement.ActivityType
import ph.gov.doe.core.product.SubproductType
/**
* This class represents a company profile's other details
*/
class CompanyProfileOtherDetails {
/** Defines a many-to-one relationship with <code>Company Profile</code> class. */
static belongsTo = [companyProfile: CompanyProfile]
/** COC number of the Company Profile */
String cocNumber
/** Defines a many-to-many relationship with <code>Activity Type and Product Type</code> class. */
static hasMany = [activityType: ActivityType, productType: ProductType, subproductTypes: SubproductType]
/** Defines validation rules, schema generation and CRUD generation meta data. */
static constraints = {
cocNumber nullable: true, unique: false, blank: true, size: 5..50, matches: /^[a-zA-Z0-9-_\/\\]+$/
activityType nullable: true , blank: true
productType nullable: true , blank: true
subproductTypes nullable: true , blank: true
}
/** Defines the way class <code>CompanyProfileOtherDetails</code>'s properties are mapped to the database. */
static mapping = {
table 'company_profile_details'
companyProfile column: 'company_profile_id'
// tradeName column :'trade_name'
// cocNumber column : 'coc_number'
}
}
这是 Activity 类型
package ph.gov.doe.core.requirement
import ph.gov.doe.core.acl.Division
/**
* This class represents an activity type.
*/
class ActivityType implements Serializable {
String name
String description
/** Flag that tells if this activity type is still active. */
boolean active = true
/** Division that sets the activity type */
Division division
/** Defines validation rules, schema generation and CRUD generation meta data. */
static constraints = {
name nullable: false, blank: false, size: 2..150, matches: "[A-Za-z0-9-. _Ññ,]+", unique: true
description nullable: false, blank: false, size: 2..255, matches: /^(?=.*[a-zA-Z0-9\Ñ\ñ].*)([a-zA-Z0-9\Ñ\ñ\.\, \_\-\~\`\!\@\#\$\%\^\&\*\(\)\+\=\{\}\[\]\|\:\;\?\/\\\<\>\"\'])+$/
division nullable: false, blank: false
}
/** Defines the way class <code>ActivityType</code>'s properties are mapped to the database. */
static mapping = {
table 'activity_type'
name name: 'name'
active name: 'is_active'
description name: 'description'
division name: 'oimb_division_id'
}
}
最佳答案
应该在动态查找器中添加inList
ActivityType.findAllByNameInList(['Distribution', 'Dealer'])
我建议你可以尝试使用动态查找器,如下面的代码
def CompanyProfileOtherDetailsInstanceList = CompanyProfileOtherDetails.createCriteria().list(){
or {
ActivityType.findAllByNameInList(['Distribution', 'Dealer']).id.each {id ->
ActivityType {
idEq(id)
}
}
}
}
(p.s. IL 表示 InstanceList)
关于java - 使用 findAll 子树意外结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55864085/