2016-01-15 38 views
2

當一個子類被重載GORM繼承導致DuplicateMappingException

package test 
class Test { 

    Integer amount 

    //static mapping = { 
    // tablePerHierarchy true 
    // autoImport false 
    //} 
} 

package test 
class Test1 extends Test{ 
    String cardNumber 
} 

父類被重載後,將創建新表的子類我的webapp的奇怪行爲

new table

但是Grails的控制檯拋出錯誤,如果我重裝子類

ERROR org.grails.plugins.AbstractGrailsPluginManager - Plugin [domainClass:3.0.9] could not reload changes to file [/home/gkiko/workspace/test/grails-app/domain/test/Test1.groovy]: Error creating bean with name 'org.grails.internal.SESSION_FACTORY_HOLDER-reloaded': Cannot create inner bean '(inner bean)#d22a35c' of type [org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean] while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d22a35c': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping test.Test1 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.grails.internal.SESSION_FACTORY_HOLDER-reloaded': Cannot create inner bean '(inner bean)#d22a35c' of type [org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean] while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d22a35c': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping test.Test1 
.... some more stacktrace 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d22a35c': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping test.Test1 

我該如何解決這一問題?

  • Grails的版本:3.0.11
  • Groovy的版本:2.4.5
  • JVM版本:1.7.0_91

回答

1

如果您正在爲您的域名進行任何更改,應重新啓動應用程序類。儘管在修改父類時它工作正常,但動態域實體創建功能仍然無法正常工作。

+0

清除數據庫架構並重新啓動應用程序將無濟於事 – gkiko

+0

你試過了嗎?這是將域更改可靠地引入Grails應用程序的唯一方法。 –

+0

@SteveHole是的,我做到了 – gkiko