3
做AddTo就*當我有域類:的Grails +斯波克:NullPointerException異常的嵌入式的hasMany場
class MarketCommoditiesConfiguration extends MarketConfiguration {
static mapWith = "mongo"
static hasMany = ['commodities': Commodity]
static embedded = ['commodities']
...
做save
addToCommodities
後拋出以下異常。
| java.lang.NullPointerException
at org.grails.datastore.mapping.model.types.Association.getInverseSide(Association.java:71)
at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.handleEmbeddedInstance(NativeEntryEntityPersister.java:1254)
at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.handleEmbeddedInstance(NativeEntryEntityPersister.java:1215)
at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.handleEmbeddedToMany(NativeEntryEntityPersister.java:1188)
at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntity(NativeEntryEntityPersister.java:1077)
at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntity(NativeEntryEntityPersister.java:1138)
at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:160)
at org.grails.datastore.mapping.core.AbstractSession.persist(AbstractSession.java:522)
at org.grails.datastore.gorm.GormInstanceApi.doSave(GormInstanceApi.groovy:194)
at org.grails.datastore.gorm.GormInstanceApi.save_closure5(GormInstanceApi.groovy:162)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
at org.grails.datastore.gorm.GormInstanceApi.save(GormInstanceApi.groovy:161)
at com.apposit.terra.connect.service.MarketService.addCommodityToMarket(MarketService.groovy:248)
at com.apposit.terra.connect.service.MarketServiceSpec.Test addCommodityToMarket creates a new next month configuration if current month's configuration doesn't exist(MarketServiceSpec.groovy:164)