Hibernate 查询可以';无法使用afterInsert查找保存的项目

Hibernate 查询可以';无法使用afterInsert查找保存的项目,hibernate,grails,gorm,gorm-mongodb,Hibernate,Grails,Gorm,Gorm Mongodb,我有一个Grails应用程序,它使用GORM保存Note域对象 我可以成功保存Note对象,但当我使用afterInsert查询包含该对象的集合时,它找不到该对象。手动查询集合时,可以看到对象已创建。发生这种情况有什么原因吗?我不明白为什么 注意 def afterInsert(){ println(id) //prints the id as expected. Matches the database def persisted = getDB().notes.findOne

我有一个Grails应用程序,它使用GORM保存Note域对象

我可以成功保存Note对象,但当我使用afterInsert查询包含该对象的集合时,它找不到该对象。手动查询集合时,可以看到对象已创建。发生这种情况有什么原因吗?我不明白为什么

注意

def afterInsert(){
    println(id) //prints the id as expected. Matches the database
    def persisted = getDB().notes.findOne(id)
    println(persisted)
            //returns null
}
noteInstance.save(flush: true, failOnError: true))
NoteService

def afterInsert(){
    println(id) //prints the id as expected. Matches the database
    def persisted = getDB().notes.findOne(id)
    println(persisted)
            //returns null
}
noteInstance.save(flush: true, failOnError: true))

withNewSession结束时没有乐趣。很难找到问题的根源Hi Travis,我也有同样的问题。你找到解决办法了吗?@Abincepto我已经有一段时间没有解决这个问题了。我没有找到使用afterinsert块的解决方案。调用save函数后,我在调用类中手动进行了调用。它可以工作,但是代码没有那么干净。谢谢你的回复。我刚刚用我的问题提出了一个新问题。