Grails searchable with join table

282 views Asked by At

I want to include domain Role in searchable. So if i using User.search() and enter authority value, system will display record.

I have 3 domains as below:

class User {
    String username
    String password
    Employee employee
    boolean accountLocked
    boolean passwordExpired

    static hasMany = [userRoles:UserRole];

    static searchable ={
        only:['username','employee','userRoles'];
        employee component:true;
        userRoles component:true;   
    }
}


class UserRole implements Serializable {

    static belongsTo = [user:User,role:Role];

    static searchable = {
       only:['role'];
       role component: true;
    }
}


class Role {
    String authority
    AccessLevel accessLevel
    ProjectName projectName

    static hasMany = [userRoles:UserRole]

    static searchable = {
       only:['authority'];
    }
}

I got this error when run app.

Error 2013-12-03 14:39:02,964 [pool-7-thread-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'compassGps': Cannot resolve reference to bean 'compass' while setting bean property 'compass'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
Message: Error creating bean with name 'compassGps': Cannot resolve reference to bean 'compass' while setting bean property 'compass'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by IllegalArgumentException: One or more invalid options were defined in 'com.atigus.admin.security.UserRole#searchable' for property 'role'. 'com.atigus.admin.security.UserRole.role' is  a [Searchable Id], meaning you can only define the options allowed for searchable references. The invalid options are: [component]. Supported options for [Searchable Id] are [accessor, converter, name]
->> 362 | validateOptions in grails.plugin.searchable.internal.compass.mapping.ClosureSearchableGrailsDomainClassCompassClassMapper
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   242 | invokeMethod in     ''
|    15 | doCall . in com.atigus.admin.security.UserRole$__clinit__closure1
|    97 | searchableGetCompassClassPropertyMappings in grails.plugin.searchable.internal.compass.mapping.ClosureSearchableGrailsDomainClassCompassClassMapper
|   129 | getCompassClassMapping in     ''
|    93 | getCompassClassMapping in grails.plugin.searchable.internal.compass.mapping.CompositeSearchableGrailsDomainClassCompassClassMapper
|    52 | getCompassClassMapping in grails.plugin.searchable.internal.compass.mapping.AbstractSearchableGrailsDomainClassCompassClassMapper
|    80 | configureMappings in grails.plugin.searchable.internal.compass.config.mapping.SearchableClassPropertySearchableGrailsDomainClassMappingConfigurator
|   131 | configure in grails.plugin.searchable.internal.compass.config.DefaultGrailsDomainClassMappingSearchableCompassConfigurator
|    39 | configure in grails.plugin.searchable.internal.compass.config.CompositeSearchableCompassConfigurator
|    93 | buildCompass in grails.plugin.searchable.internal.compass.spring.SearchableCompassFactoryBean
|    58 | getObject in     ''
|   303 | innerRun in java.util.concurrent.FutureTask$Sync
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread

No idea how to resolve this prob. No answer found in google.

1

There are 1 answers

3
haedes On

I think the searchable parameters in your userrole class are invalid.
Initially just try static searchable = true
in the userrole domain. This should be enough.