gpt4 book ai didi

grails - grails 中不可预测的 "Could not synchronize database state with session"异常

转载 作者:行者123 更新时间:2023-12-02 02:20:39 27 4
gpt4 key购买 nike

我开始在日志中看到“无法将数据库状态与 session 同步”异常,并且很难重现它。有时它工作正常......我看到两个异常(它们发生在不同的时间):

ERROR JDBCExceptionReporter - Deadlock found when trying to get lock; try restarting transaction ERROR PatchedDefaultFlushEventListener - Could not synchronize database state with session org.hibernate.exception.LockAcquisitionException: could not update: [com.myapp.School#1911]

还有

ERROR PatchedDefaultFlushEventListener - Could not synchronize database state with session org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.myapp.School#1905]

这是抛出它们的方法:

def populateFriends(ArrayList<FriendView> friends, User user) {

friends.eachWithIndex { friendView, index ->

def friend = Friend.findByFriendId(friendView.id) ?: new Friend()
def schoolName = friendView.schoolName
def school = null
if (schoolName) {
school = School.findByName(schoolName) ?: new School(name: schoolName).save(flush:true)
}
if (school) {
// add to user's school list
user = User.get(user.id)
user.addToSchools(school)
user = user.merge(flush: true)
user.save(flush: true)

friend.school = school
}
friend.save(flush: true)
}
}

我一整天都在做这件事,非常感谢任何帮助。

最佳答案

这里的答案是使用lock:true。

School.findByName(name, [lock: true])

关于grails - grails 中不可预测的 "Could not synchronize database state with session"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11218554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com