2013-12-03 5 views
0

Я хочу включить роль домена в поиск. Поэтому, если я использую User.search() и введите значение полномочий, система отобразит запись.Grails searchable with join table

У меня есть 3 домена, как показано ниже:

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

Я получил эту ошибку при запуске приложения.

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 

Не знаю, как решить эту проблему. В Google не найдено ответа.

ответ

0

Я думаю, что поисковые параметры в вашем классе userrole недопустимы.
Сначала попробуйте static searchable = true
в домене userrole. Этого должно быть достаточно.

+0

Уже не пытаться вернуть эту ошибку: Нет преобразователя, определенный для типа [com.atigus.admin.security.Role] – syah

+0

Попробуйте использовать 'статических для поиска = true' как для пользователя и домен роли – haedes

+0

еще же вероят. Один или несколько недопустимых параметров были определены в 'com.atigus.admin.security.UserRole # searchable' для свойства 'role' – syah