java - 使用 findAll 子树意外结束

标签 java grails findall

我正在处理我的 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/

相关文章:

grails - 从 GroovyShell 脚本访问 Grails 域类

Python findall() 起始数字和结束单词

python - 使用 BeautifulSoup 提取带有嵌入链接的文本

java - Spring jpa @OneToMany 一个方向始终为 null

jakarta-ee - 将Grails应用程序作为一个war文件部署在另一个Java EE Web应用程序中

java - 尝试使用 Smackx pubsub 获取节点时出现 item-not-found(404)

mysql - 如何强制 Grails 在 MySQL 中为 Map 字段使用正确的列类型

python - 用单引号或双引号在 Python 中提取字符串

java - RMI 或套接字连接到 OpenShift 上的 Java 程序

java - 如何使 JOptionPane 在尝试关闭 JFrame 时出现