【问题标题】:unexpected end of subtree using findAll使用 findAll 意外结束子树
【发布时间】:2019-04-26 08:54:23
【问题描述】:

我正在处理我的 grails 项目,并且想要检索所有具有特定活动类型的 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'
}
}

这是活动类型

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'
    }
}

【问题讨论】:

    标签: java grails findall


    【解决方案1】:

    应该在动态查找器中添加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)

    【讨论】:

    • 感谢您的回复先生,但它有一个错误说“消息:没有为参数1指定值”。
    • 我能看到你的 grails.domain 类 CompanyProfileOtherDetails 和 ActivityType
    • 我在这里找到了一个可能的解决方案,我无法尝试(我的项目数据库没有创建 realaction)我有上面的示例代码(在帖子中更新)ryanalberts.com/92/grails-findby-for-hasmany-relationship
    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 2010-12-27
    • 1970-01-01
    • 2011-01-05
    • 2019-12-25
    • 2014-03-27
    • 1970-01-01
    • 2011-06-03
    相关资源
    最近更新 更多