2016-04-25 14 views
2

当试图运行命令grails run-app --stacktrace,Grails是引发此错误:ClassCastException异常的MappingFactory以一对多到Grails的3

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从所有域类,但错误依然坚持着,直到我取代了它与Hibernate3的build.gradle

我怎么可以这样使用hibernate4解决?

回答

0

我找到了解决办法,其实它与embedded grails domain property做。

+0

问题的解决方案是什么? –

+0

我来到这里想知道@KevinTan同样的事情 – genuinefafa

0

作为@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嵌入类具有与容器类相同的数据源。