Grails" MappingException:未知实体"在继承的类中

时间:2017-06-22 21:03:44

标签: hibernate grails grails-2.0 grails-domain-class single-table-inheritance

我在Grails 2.5.5中获得了一些课程(简化):

class Solution implements Serializable {
    long id
    String name

    static hasOne = [
        entity : SolutionEntity
    ]

    static mapping = {
        datasource 'companion'
        id generator:'sequence', params:[sequence: 'SOLUTION_SEQ']
        entity cascade: 'delete'
    }

    static constraints = {
        name nullable: true, blank:false, unique: true
        entity nullable: true
    }
}

class SolutionEntity implements Serializable {
    Solution solution

    Long externalEntityId
    private Object externalEntity

    void setExternalEntity(def value){
        externalEntityId = value.id
    }

    static transients = ["externalEntity"]

    static constraints = {
        solution nullable: false, unique: true
        externalEntityId nullable: false
    }

    static mapping = {
        datasource 'companion'
        id generator:'sequence', params:[sequence: 'SOLUTION_ENTITY_SEQ']
        tablePerHierarchy true
    }
}

class SolutionPPB extends SolutionEntity implements Serializable {

    PPB getPPB(){
        if(!externalEntity && externalEntityId) {
            externalEntity = PPB.get(externalEntityId)
        }
        externalEntity
    }

    static constraints = {
    }
}

我的基本想法是,我想将每个SolutionSolutionEntity相关联,PPB可能属于不同的类型(我在此处显示PPB)。这是基于Burt Beckwith的recommendation,因为Solution位于不同的数据源中。我可以根据自己的喜好创建和修改SolutionEntity条目,但似乎没有任何问题。但是,当我尝试创建这样的def link = SolutionPPB.findOrCreateBySolution(solution) link.setExternalEntity(entity) link.save(failOnError: false) 对象时:

org.springframework.orm.hibernate4.HibernateSystemException: Unknown entity: myapp.Solution; nested exception is org.hibernate.MappingException: Unknown entity: myapp.Solution

我得到例外:

Solution

我无法弄清楚我做错了什么。由于我在尝试链接Solution之前没有遇到任何问题,因此{{1}}未知,这似乎令人惊讶。

0 个答案:

没有答案