简体   繁体   中英

Spring Security Plug-in Doesn't Work With More Than One BelongsTo. Why?

I have a class like this :

class User {
    String name;
    String password;    
    static hasMany = [ authorities : testing.Role ]
    static belongsTo = Role
    static constraints = {
    name(unique:true,size:4..10)
    }
}

I have configured Spring Security Plugin(acegi) and ya its working as expected. But the problem is that when I change my belongsTo in User class to something like this :

static belongsTo = [ Role , company : Company]

And I tried running grails run-app I get error like this :

/home/anto/anto/test/testing/grails-app/domain/testing/User.groovy: 7: Unexpected node type: EXPR found when expecting type: LABELED_ARG at line: 7 column: 25. File: /home/anto/anto/test/testing/grails-app/domain/testing/User.groovy @ line 7, column 25.
       static belongsTo = [Role , company : Company ] 
                           ^

1 error

Why this syntax throwing an error? Where I have made a mistake?

Edit:

Now after getting answers from few, I changed my code into :

static belongsTo = [ role: Role , company : Company]

But this time I'm getting even a bigger error!

2011-12-31 14:23:57,304 [Thread-9] ERROR context.ContextLoader  - Context initialization failed 
Message: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain classes [class testing.Role] and [class testing.User] in a many-to-many relationship. Example: static belongsTo = testing.User 
   Line | Method 
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask 
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   908 | run      in     '' 
^   662 | run . .  in java.lang.Thread 

Caused by GrailsDomainException: No owner defined between domain classes [class testing.Role] and [class testing.User] in a many-to-many relationship. Example: static belongsTo = testing.User 
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask 
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   908 | run      in     '' 
^   662 | run . .  in java.lang.Thread 
| Error 2011-12-31 14:23:57,401 [Thread-9] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain classes [class testing.Role] and [class testing.User] in a many-to-many relationship. Example: static belongsTo = testing.User 
Message: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain classes [class testing.Role] and [class testing.User] in a many-to-many relationship. Example: static belongsTo = testing.User 
   Line | Method 
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask 
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   908 | run      in     '' 
^   662 | run . .  in java.lang.Thread 

Caused by GrailsDomainException: No owner defined between domain classes [class testing.Role] and [class testing.User] in a many-to-many relationship. Example: static belongsTo = testing.User 
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask 
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker 
|   908 | run      in     '' 
^   662 | run . .  in java.lang.Thread

Now, whats happening?

But if I do something like this :

static belongsTo = Role

Everything is working fine. And I dont know why the previous syntax thrown such an error!

I'm a beginner in Grails and I need a help.

Note: I'm using Grails 2.0

Thanks in advance.

This isn't a security issue at all, it's a GORM issue. [ Role , company : Company] makes no sense, since you're mixing Groovy's List syntax ( [Foo, Bar, Baz] ) with its Map syntax ( [foo: Foo, bar: Bar, baz: Baz] ). You have to pick one.

它应该是static belongsTo = [role: Role , company : Company ]吗?

The stacktrace seems to suggest that the problem is in the other side of the relation. How do the Role and Company classes look? They both should have a property like 'User user'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM