gpt4 book ai didi

hibernate - Grails和Hibernate:未知实体:com.mypackage.Role

转载 作者:行者123 更新时间:2023-12-02 14:43:37 25 4
gpt4 key购买 nike

我有一个grails应用程序。我已经安装了Spring Security Core插件2.0 RC2,并且正在BootStrap.groovy中创建角色,用户和requestmap。
我运行应用程序时,Grails抛出以下错误。

ERROR context.GrailsContextLoader  - Error initializing the application: Unknown entity: Role

这是我的Role类(由spring安全插件生成,并经过修改以扩展AbstractActivity,它是一个具有beforeInsert()方法/ closure并进行一些验证的抽象类)。
package com.mypackage

class Role extends AbstractDomain {

String authority

Date dateCreated
Date lastUpdated
User createdBy
User updatedBy

static mapping = {
cache true
}

static constraints = {
authority blank: false, unique: true

createdBy nullable: true
updatedBy nullable: true
}
}

抽象域
package com.mypackage

import com.mypackage.User

class AbstractDomain implements Serializable {

transient springSecurityService

def beforeInsert() {

if(null != springSecurityService) {

User user = springSecurityService.getCurrentUser()

if(null != user) {

this.createdBy = user
}
}
}

}

BootStrap.groovy
import com.mypackage.Role

class BootStrap {
def init = { servletContext ->
if (Role.findByAuthority('ROLE_ADMIN') == null)
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
}
def destroy = {}
}

配置槽
grails.plugin.springsecurity.userLookup.userDomainClassName ='com.mypackage.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName 'com.mypackage.UserRole'
grails.plugin.springsecurity.authority.className = 'com.mypackage.Role'
grails.plugin.springsecurity.requestMap.className = 'com.mypackage.Requestmap'
grails.plugin.springsecurity.securityConfigType = 'Requestmap'

如何解决未知实体问题?

最佳答案

我找到了解决方案!
我的RoleDomain类扩展的AbstractDomain类位于“src / groovy”文件夹中,我忘了使其“抽象”。然后我在abstract之前添加了class关键字,它的工作原理就像魔术。感谢@mgg给我的想法here

所以,我的AbstractDomain类现在看起来像

abstract class AbstractDomain implements Serializable {
...

关于hibernate - Grails和Hibernate:未知实体:com.mypackage.Role,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22806774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com