UUID com MongoDB
02/12/2011 15:36
0
Olá Pessoal estou tentando criar uma classe de domínio conforme código abaixo e esta me retornando uma exceção

package mongoteste

class Fornecedor {

String id

static constraints = {
}

static mapping = {
id generator:'uuid'
}

}


Erro:

ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
at RunApp$_run_closure1.doCall(RunApp.groovy:33)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
... 23 more
Caused by: java.lang.NullPointerException
at org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.isExcludedProperty(GormMappingConfigurationStrategy.java:662)
at org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.getPersistentProperties(GormMappingConfigurationStrategy.java:173)
at org.grails.datastore.mapping.model.AbstractPersistentEntity.initialize(AbstractPersistentEntity.java:80)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntityInternal(AbstractMappingContext.java:150)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:135)
at org.grails.datastore.mapping.model.MappingContext$addPersistentEntity.call(Unknown Source)
at org.grails.datastore.gorm.bean.factory.AbstractMappingContextFactoryBean.getObject(AbstractMappingContextFactoryBean.groovy:63)
at org.grails.datastore.gorm.bean.factory.AbstractMappingContextFactoryBean.getObject(AbstractMappingContextFactoryBean.groovy)
... 23 more
Tags: MongoDB, UUID


0
Bom tentei assim e de erro também

package mongoteste

class Fornecedor {

String uniqueIdentifier

static constraints = {
uniqueIdentifier(nullable:true)
}

transient beforeInsert = {
uniqueIdentifier = java.util.UUID.randomUUID().toString()
}

}


erro:
,java.lang.IllegalArgumentException: can't serialize class mongoteste.Fornecedor$_closure1
at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:234)
at org.bson.BSONEncoder.putObject(BSONEncoder.java:140)
at org.bson.BSONEncoder.putObject(BSONEncoder.java:86)
at com.mongodb.OutMessage.putObject(OutMessage.java:190)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:253)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:217)
at org.grails.datastore.mapping.mongo.MongoSession$1.doInDB(MongoSession.java:149)
at org.grails.datastore.mapping.mongo.MongoSession.flushPendingInserts(MongoSession.java:125)
at org.grails.datastore.mapping.core.AbstractSession.flush(AbstractSession.java:237)
at org.grails.datastore.mapping.core.Session$flush.call(Unknown Source)
at org.grails.datastore.gorm.GormInstanceApi.doSave(GormInstanceApi.groovy:168)
at org.grails.datastore.gorm.GormInstanceApi$_save_closure4.doCall(GormInstanceApi.groovy:143)
at $Proxy9.doInSession(Unknown Source)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:301)
at org.grails.datastore.mapping.core.DatastoreUtils$execute.call(Unknown Source)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:34)
at org.grails.datastore.gorm.GormInstanceApi.save(GormInstanceApi.groovy:142)
at org.grails.datastore.gorm.InstanceMethodInvokingClosure.call(GormEnhancer.groovy:248)
at mongoteste.FornecedorController$_closure4.doCall(script13228421871172103442911.groovy:24)
at mongoteste.FornecedorController$_closure4.doCall(script13228421871172103442911.groovy)
at java.lang.Thread.run(Thread.java:662)




Ainda não faz parte da comunidade???

Para se registrar, clique aqui.


Aprenda Groovy e Grails com a Formação itexto!

Newsletter Semana Groovy

Assinar

Envie seu link!


Livro de Grails


/dev/All

Os melhores blogs de TI (e em português) em um único lugar!

 
Creative Commons
RSS Grails Brasil é mantido por itexto Consultoria.
Em caso de problemas contacte Henrique Lobo Weissmann (Kico) por e-mail: kico@itexto.com.br
Todo o conteúdo presente neste site adota o Creative Commons como licença padrão.
Ver: 4.14.0
itexto