Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 扩展域类会导致奇怪的表布局和不可访问的字段_Hibernate_Grails_Grails Domain Class - Fatal编程技术网

Hibernate 扩展域类会导致奇怪的表布局和不可访问的字段

Hibernate 扩展域类会导致奇怪的表布局和不可访问的字段,hibernate,grails,grails-domain-class,Hibernate,Grails,Grails Domain Class,我有一个定义为的域类用户 class User extends SecUser{ String fullName String address String city String country String role String email String schoolName String gradeLevel static constraints = { fullName(nullable:true

我有一个定义为的域类用户

class User extends SecUser{
    String fullName
    String address
    String city
    String country
    String role
    String email
    String schoolName
    String gradeLevel

    static constraints = {
        fullName(nullable:true)
        username(blank:false, unique:true)
        password(size:6..20, blank:false)
        //passwordRepeat(validator:)
        email(email:true, nullable:true, unique:true)
        address(nullable:true)
        city(nullable:true)
        country(nullable:true)
        phone(nullable:true) //10 digit phone number, no spaces
        role(blank:false, inList:['Teacher', 'Donor', 'Both'])
        schoolName(nullable:true)
        gradeLevel(nullable:true, inList:['K', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', 'College'])

    }
}
class SecUser {

    transient springSecurityService

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

    static constraints = {
        username blank: false, unique: true
            password blank: false
    }
}
SecUser是通过执行springsecuritygrails插件的快速启动脚本实现的类。其定义为

class User extends SecUser{
    String fullName
    String address
    String city
    String country
    String role
    String email
    String schoolName
    String gradeLevel

    static constraints = {
        fullName(nullable:true)
        username(blank:false, unique:true)
        password(size:6..20, blank:false)
        //passwordRepeat(validator:)
        email(email:true, nullable:true, unique:true)
        address(nullable:true)
        city(nullable:true)
        country(nullable:true)
        phone(nullable:true) //10 digit phone number, no spaces
        role(blank:false, inList:['Teacher', 'Donor', 'Both'])
        schoolName(nullable:true)
        gradeLevel(nullable:true, inList:['K', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', 'College'])

    }
}
class SecUser {

    transient springSecurityService

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

    static constraints = {
        username blank: false, unique: true
            password blank: false
    }
}
通常,我认为生成的数据库表将是一个用户表,上面列出的字段作为列,我可以使用UserController方法实现CRUD。问题是,从未创建用户表,而是用上述字段实例化了secu用户表

我的问题与创建新用户和填充相关字段有关。由于用户表不存在,因此无法插入来自用户域对象的记录

另一方面,我可以在secu USER表中插入记录,但字段仅限于SecUser domain类中定义的字段。如果我试图通过一个新的SecUser实例在User中的特定列中插入一个项,我会收到一条property not defined错误消息


这有点令人沮丧,因为为了完成用户注册过程,我需要访问、插入和更新相关字段,但如何在没有访问权限的情况下做到这一点?

我相信您要寻找的是每个子类映射的表,而不是每个层次结构的默认表

每个层次结构的默认表可能会使处理数据库变得困难 另一个缺点是列不能在db级别应用“NOTNULL”约束

grails对此有一点评论。。。。在5.5.2.3继承策略中

如果将以下内容添加到域类中,则每个子类将获得一个表

 static mapping = {
    tablePerHierarchy false
 }