如何在域中導入服務?如何在域中導入服務?
它有一個字段,我需要填寫一個協議字段。該協議是自動生成的,併爲這一代創建了一項服務排除事項。
在方法'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
什麼是postService.teste的內容? –
只是一個函數更改協議屬性: 高清泰斯特(後後){ post.protocolo =「START」 } – isilva