【问题标题】:ClassCastException for MappingFactory to ToMany while porting to grails 3移植到 grails 3 时 MappingFactory 到 ToMany 的 ClassCastException
【发布时间】:2016-08-18 19:29:31
【问题描述】:

当尝试运行命令grails run-app --stacktrace 时,grails 抛出此错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.ClassCastException: org.grails.datastore.mapping.model.MappingFactory$10 cannot be cast to org.grails.datastore.mapping.model.types.ToMany

我从所有域类中评论了static hasMany,但错误仍然存​​在,直到我在我的build.gradle

中将其替换为 hibernate3

如何使用 hibernate4 解决这个问题?

【问题讨论】:

    标签: grails grails-orm datastore hibernate-4.x grails-3.1


    【解决方案1】:

    我找到了解决方案,实际上它与embedded grails domain property有关。

    【讨论】:

    • 问题的解决方法是什么?
    【解决方案2】:

    正如@deepen 提到的,此错误与嵌入式域类的映射设置有关。就我而言,我使用的是多个数据库(mongodb gorm 6.0.12 + jtds (sql server)),并且一些文档具有嵌入式属性(在同一类中定义)。

    DomainA.groovy
    class DomainA
        static hasMany = [domainBs: DomainB]
        static embedded = ['domainBs']
        static mapWith = "mongo"
    
    class DomainB
        // if embedded: what's the point of this? 
        static belongsTo = [domainB: DomainA]
        // if i'll use it as embedded, doesn't add nothing
        static mapWith = "mongo"
    

    简而言之,如果我在嵌入类的定义中注释belongsTomapWith,问题就解决了。如果没有,必须记得mapWith嵌入类与容器类具有相同的数据源。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      相关资源
      最近更新 更多