如何解决在发生异常后不刷新会话

时间:2014-03-05 10:15:33

标签: hibernate session grails gorm

这是我的代码

try {
  if(request.currentOrganization) {
    Test test = new Test()
    test.organization = request.currentOrganization
    test.save()
  }
} catch(Exception ignoreMe) {
     //println("Unable to update notification table : " + ignoreMe.message)
}

这里没有必要这样做,看起来很奇怪,这个话题的其他一些答案对我没有帮助,有人可以帮我解决这个问题

异常

org.hibernate.AssertionFailure: null id in com.rwi.base.test entry (don't flush the Session after an exception occurs

2 个答案:

答案 0 :(得分:1)

看起来你的request.currentOrganization与hibernate会话分离了。要修复它,您可以使用:

def organization = Organization.get( request.currentOrganization.id )
notification.organization = organization

答案 1 :(得分:0)

问题可能是您在DailyServiceNotification中已经确定了Java中的null并且您正试图将其保留,但数据库中的相应列为NOT NULL

相关问题