以下のようなエラー
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
instantiating bean of type [org.grails.orm.hibernate.HibernateDatastore]: Duplicate property mapping of _booksIndexBackref found in domain.Book io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [org.grails.orm.hibernate.HibernateDatastore] could not be loaded: Error instantiating bean of type [org.grails.orm.hibernate.HibernateDatastore]: Duplicate property mapping of _booksIndexBackref found in domain.Book at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1549) at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:220) at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2812) at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:233) at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:166) at io.micronaut.runtime.Micronaut.start(Micronaut.java:71) Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [org.grails.orm.hibernate.HibernateDatastore]: Duplicate property mapping of _booksIndexBackref found in domain.Book at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1927) at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2679) at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2215) at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1543) ... 6 common frames omitted Caused by: org.hibernate.MappingException: Duplicate property mapping of _booksIndexBackref found in domain.Book at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:643) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:633) at org.hibernate.mapping.RootClass.validate(RootClass.java:267) at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:354) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708) at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:287) at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86) at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:39) at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:23) at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64) at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52) at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24) at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:212) at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:233) at io.micronaut.configuration.hibernate.gorm.HibernateDatastoreFactory.hibernateDatastore(HibernateDatastoreFactory.groovy:63) at io.micronaut.configuration.hibernate.gorm.$HibernateDatastoreFactory$HibernateDatastore0Definition.build(Unknown Source) at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898) ... 9 common frames omitted |
原因は、hasMany で持ってる子のデータの順序を担保するために、Listで保持していたがその時の名前が被っていたため。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class Book { } class Author { List books = [] static hasMany =[books: Book] } class BookStore { List books = [] static hasMany =[books: Book] } |
このようにすると、 Book テーブルに、 books_idx というカラムを複数作ろうしてエラーになる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class Book { } class Author { List books = [] static hasMany =[books: Book] } class BookStore { List bookList = [] static hasMany =[bookList: Book] } |
このように、名前を変更すれば、
Book テーブル には、 books_idx と、 books_list_idx となるのでエラーを避けられる。