Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8830005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:58:02+00:00 2026-06-14T07:58:02+00:00

I am starting to see Could not synchronize database state with session exceptions in

  • 0

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):

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]

And

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]

Here is the method where they are thrown:

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)
    }
}

I’ve been at this all day and I’d really appreciate any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:58:03+00:00Added an answer on June 14, 2026 at 7:58 am

    The answer here is to use lock:true.

    School.findByName(name, [lock: true])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting a new project that involves users paying to see educational videos. These
I am starting to learn about makefiles. Looking at the output I see a
Updated question, see below I'm starting a new project and I would like to
I am having a terrible time understanding how to get the wrapper to work
I am looking to see if this could come back to bite me in
I googled a lot and read through the wiki, just could not find out
I'm starting to see the value of Interfaces vs. lets say an Abstract class.
I had recently a problem with oom-killer starting to kill processes after some time.
Ok i've to admin i'm not a master in recursion. This could be kinda
Maybe I am just blind, but I do not see how to use Guice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.