hibernate - GORM in Grails and StaleObjectStateException -


I'm writing a small Grails app, and I'm getting StaleObjectStateException: s about 1/10: To call "createfoo" when the following simple code is running most probably I'm missing the best way to use the goram.

This code is:

  def viewfoo = {session.user.refresh () // ...} def createfoo = {session.user.refresh () var User = session.user if (the ultimate ["name"]) {var newFoo = new Foo () newFoo.name = param ["name"] if (NewFoo.validate ()) {newFoo.save () if (user. Validate ()) {user.addToFoos (newFoo)} and {user.discard ()}} else {newFoo.discard ()}}}  

About the best practices of GOM Question:

  1. What is the "valid" certified () - then-save () -ad-diskcard () "what is the right way to create a new object in the GOM ?

  2. Should I validate all the objects that I am about to save? To wit. Should I validate both Foo Object and User object in the above code? Should the status of the foo object be checked by validating user-object?

  3. What did I do to be eligible for StaleObjectStateException? : -)

Gorem / Hibernate exception:

 Reason: The purpose of the square [FU] with the identifier [15]: optimistic locking failed; Nested exception org.hibernate.StaleObjectStateException: the line was updated or deleted by another transaction (or unsaved-value mapping): [Foo # 15] 

I'm not sure why you're killing the problems, but there is a method on the domain object, it lets you add existing objects again in the current continuous context is.

I do not have enough information about what your fu is, or whatever customization you have done for user object, or version of Giles / Java you are using to be able to reproduce it .

I'm thinking that there is something to refresh on the user's object that is causing the database to be updated to the version (and thus out of sync), but I can not believe it is.

In addition, I believe that if validated, abandon the behavior and at least Grails 1.1 is changing based on observations


Comments