2016-04-25 35 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嵌入類具有與容器類相同的數據源。