开发者

help on error org.hibernate.StaleObjectStateException

Please help me get around this error . It comes sometimes at other times it does. I know its because of concurrent requests but how to overcome it ?? 开发者_运维技巧I tried lock instead of get but it did not work.

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):

My code is :

def principal = springSecurityService.principal
    if (principal instanceof String)
        return null
    else {
        def user = NayaxUser.get(principal.id)
        user.merge()
        return user
    }

I have also tried using merge , but nothing seems to help.. Any suggestions ??


One thing I notice is that your code

user.merge()
return user

seems problematic, because as is specified in http://grails.org/doc/latest/ref/Domain%20Classes/merge.html:

Unlike the save method this method returns a new instance of the class representing the re-attached object. [...] If you don't use the return value of the merge method then you still have access to the original detached instance and you will get errors such as lazy initialization exceptions.

So the correct code in your case would be

return user.merge()

However, I'm not sure whether this solves your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜