Note that there are some explanatory texts on larger screens.

plurals
  1. POUnpredictable "Could not synchronize database state with session" exceptions in grails
    text
    copied!<p>I am starting to see "Could not synchronize database state with session" exceptions in my logs and I'm having a hard time reproducing it. Sometimes it works fine... I am seeing two exceptions (they are happening at different times):</p> <blockquote> <p>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]</p> </blockquote> <p>And</p> <blockquote> <p>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]</p> </blockquote> <p>Here is the method where they are thrown:</p> <pre><code>def populateFriends(ArrayList&lt;FriendView&gt; friends, User user) { friends.eachWithIndex { friendView, index -&gt; 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) } } </code></pre> <p>I've been at this all day and I'd really appreciate any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload