Grails 向SpringSecurity用户类添加关联

Grails 向SpringSecurity用户类添加关联,grails,spring-security,gorm,Grails,Spring Security,Gorm,我正在尝试添加一个从默认SpringSecurity用户域类到另一个类的引用,该类应该包含其他用户信息 class User { transient springSecurityService String username String password boolean enabled boolean accountExpired boolean accountLocked boolean passwordExpired Pr

我正在尝试添加一个从默认SpringSecurity用户域类到另一个类的引用,该类应该包含其他用户信息

class User {
    transient springSecurityService

    String username
    String password
    boolean enabled
    boolean accountExpired
    boolean accountLocked
    boolean passwordExpired

    Profile profile
      ...
……还有

class Profile {
    static constraints = {
    }

    static belongsTo = [user : User]

    String firstName
    String lastName     
}
据我所知,这应该是它的工作方式,但我得到以下错误:

ERROR context.GrailsContextLoader  - Error executing bootstraps: null
Message: null
   Line | Method
->>  32 | create                           in com.app.UserRole
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    15 | doCall                           in BootStrap$_closure1
|   301 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|   294 | executeForEnvironment            in     ''
|   270 | executeForCurrentEnvironment . . in     ''
|   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

有什么想法吗

我们需要查看您的
引导程序才能确定,但我怀疑这是因为您正在执行类似的操作

def user = new User(....).save()
def role = new Role(....).save()
UserRole.create(user, role)
新的
用户
验证失败(这会导致
保存
返回


如果您使用
save(failOnError:true)
您应该会得到一个不同的异常,更好地说明真正的问题是什么。检查您在
用户
类中是否有正确的
约束
,特别要注意,GORM属性在默认情况下是不可为空的,因此如果您希望能够保存没有
配置文件的
用户
,则需要添加
配置文件的约束(可为空:true)

我们确实需要查看您的
引导程序,但我怀疑这是因为您正在执行类似的操作

def user = new User(....).save()
def role = new Role(....).save()
UserRole.create(user, role)
新的
用户
验证失败(这会导致
保存
返回


如果您使用
save(failOnError:true)
您应该会得到一个不同的异常,更好地说明真正的问题是什么。检查您在
用户
类中是否有正确的
约束
,特别要注意,GORM属性在默认情况下是不可为空的,因此如果您希望能够保存没有
配置文件的
用户
,则需要添加
配置文件的约束(可为空:true)

请向我们展示您从BoorStrap.groovy生成代码时的错误…请向我们展示您从BoorStrap.groovy生成代码时的错误…设置可空:true约束完成了此操作。非常感谢你!设置nullable:true约束实现了这一点。非常感谢你!