如何在域中导入服务?
它有一个字段,我需要用协议填写一个字段。该协议是自动生成的,并为这一代创建了一个服务excluvivamente。
在方法“AfterInsert”的字段中插入了对该服务的调用,该服务会自动填充该字段。
我启动了一些对象的创建,这些对象需要使用此协议填充到您的字段中。但是发生了一个错误,这显然是由于在“域”中使用了“服务”。有人可以帮我吗?
class Post {
static transient postService
String conteudo
Date dataCriacao = new Date()
String protocolo
static constraints = {
dataCriacao(nullable:false, blank:false)
conteudo nullable:false, blank: false
protocolo nullable: true, blank: true
}
static mapping = {
conteudo type: 'text'
sort dataCriacao:"desc"
}
def afterInsert(){
if(!this.protocolo){
registraProtocolo()
}
}
protected void registraProtocolo() {
postService.teste(this)
}
}
Error: ERROR hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
Message: null id in com.app.post.Post entry (don't flush the Session after an exception occurs)
Line | Method
->> 105 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
Message: null id in com.app.post.Post entry (don't flush the Session after an exception occurs)
Line | Method
->> 105 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 27 | recInsertProtocolo in com.app.post.PostService
| 83 | teste . . . . . . in ''
| 117 | registraProtocolo in com.app.post.Post