So, what the hell happens when you try and save changes to an @Version’d entity when another thread saves it’s changes before you?

Imagine you’re setup with a JPA 2 environment, using Spring Data JPA and Hibernate is your JPA vendor. You have a UserRepository interface which extends JpaRepository and therefore a Spring generated userRepository bean for all your user DAO needs. You also have a User domain object with a field annotated with @Version.

FYI, your find, save, delete etc. methods in your userRepository are automatically @Transactional. Thank you, Spring.

Ok, lets formalise this a bit:

Thread 1 finds User record with ID 1
Thread 2 finds User record with ID 1
Thread 2 changes the email address field
Thread 2 saves the changes to their version of the user object
Thread 1 changes the email address field
Thread 1 saves the changes to their version of the user object

At the point where thread 1 saves changes, it’ll check the version field of the user object and also the version of the user object in the database. They’ll be different, and a HibernateOptimisticLockingFailureException will be thrown.

Note also that the exact same thing happens if either thread 1 or thread 2 had deleted the object. So, all well and good huh? Check this out for sensible:

Thread 1 finds User record with ID 1
Thread 2 finds User record with ID 1
Thread 2 changes the email address field
Thread 2 saves the changes to their version of the user object
Thread 1 changes nothing, but then saves their version of the user object

What happens here? I originally thought thread 1 would throw an optimistic locking exception. Except, it doesn’t – Spring/JPA/whoever is in charge back there is smart enough to know that nothing changed, so it doesn’t save anything, and you end up with thread 2′s changes as you wanted. Clever girl.

13 thoughts on “So, what the hell happens when you try and save changes to an @Version’d entity when another thread saves it’s changes before you?

  1. Prolactin induced suppression of the gonadotrophin releasing hormone pulse generator may have contributed priligy canada Eugenio BFsIjZMjoBS 5 29 2022

  2. SOIL WATER AND FOOD BORNE DISEASES priligy and cialis together All patients were questioned for adverse events

  3. The American Society of Clinical Oncology ASCO has updated its guidelines on adjuvant hormonal therapy recommending postmenopausal women diagnosed with early stage hormone receptor positive breast cancer that has spread to the lymph nodes node positive disease be treated with hormonal therapy including an aromatase inhibitor for 10 years after surgery priligy tablets price

  4. If you have a 10 pound dog they may only drink cup of water per day while a 100 pound dog may drink 2 to 4 liters per day which is almost 9 cups to just over 19 cups of water per day order priligy online uk Ranweiler R

  5. Das als „österreichisches Monte Carlo“ bekannte Casino bietet eine Vielzahl von Spielmöglichkeiten,
    darunter rund 230 Spielautomaten und 15 Live-Spieltische mit Klassikern wie American Roulette, Blackjack und Poker.
    Ein kulinarischer Kalender bietet Verkostungen zu unterschiedlichen Themen.
    Cash Games werden regelmäßig mit unterschiedlichen Buy-Ins in den Varianten No Limit
    Hold’em, Omaha Pot Limit und Seven Card Stud gespielt.

    Casino Velden online verfügt über 15 Live-Spieltische mit einer Reihe von klassischen Tischspielen, die ein authentisches und fesselndes Erlebnis versprechen. Mit Einsätzen ab 0,75 € sind
    die Spielautomaten für Gelegenheitsspieler leicht
    zugänglich, bieten aber auch Optionen mit hohen Einsätzen für diejenigen,
    die eine spannende Herausforderung suchen. Die mobile Anwendung des Casino Velden bietet eine
    bequeme Möglichkeit für Gäste, mit den Dienstleistungen des Casinos in Verbindung zu bleiben. Als
    konzessioniertes Unternehmen im Rahmen der österreichischen Glücksspielregulierung arbeitet das Casino Velden mit voller Transparenz
    und unter Einhaltung strenger gesetzlicher Auflagen.
    Wer ohne Menü planen möchte, findet in der direkten Umgebung zusätzliche Restaurants in Gehdistanz.
    Die gastronomische Ausrichtung kann saisonal angepasst werden; Reservierungen sind an Wochenenden und in der Hauptsaison empfehlenswert.

    Für Gäste, die einen planbaren Abend mit Kulinarik und anschließendem Spiel bevorzugen,
    ist dies ein strukturierter Einstieg. Für ernsthafte Pokerinnen und Pokerer empfiehlt sich
    daher eine frühzeitige Planung, inklusive Hotel- und Tischreservierung zu stark frequentierten Zeiten. Diese Parameter können je nach Tisch/Tag
    variieren und sollten vor dem Setzen am jeweiligen Tisch erfragt werden.

    References:
    https://online-spielhallen.de/amunra-casino-freispiele-ihr-schlussel-zum-spielspas/

  6. The casino’s jackpot winners often share positive experiences regarding prize payouts
    and verification processes. Level Up Casino has built a solid reputation among Australian players since launching
    in 2020, with ratings based on over 2,195 community member votes and feedback from 84 real players.
    Our table games section includes multiple variants
    of blackjack, roulette, and baccarat. We feature progressive slots with massive jackpots alongside video poker variants for strategic players.
    Our extensive collection spans all major game categories with titles from industry giants like NetEnt,
    Microgaming, and Pragmatic Play.
    The help centre includes detailed guides for payment methods, responsible gambling
    tools, and verification requirements. Our support team responds
    within 10 minutes via live chat and 6 hours for email enquiries.
    Level Up Casino delivers round-the-clock assistance
    through multiple channels including instant live chat and comprehensive self-service resources.
    We require identity verification including photo ID and proof of
    address before processing withdrawal requests.
    At casino, we understand the importance of providing our Australian players with
    a seamless and secure banking experience. Game Suppliers
    One of the key factors in the success of any online casino is the availability of high-quality and diverse games.

    These games feature simple mechanics, making them particularly appealing to users who prefer a fast-paced gaming experience.

    By making a deposit on the weekends, players can claim a 50%
    bonus up to $500 AUD, along with 75 free spins.
    On the first deposit, players can claim a 100% match bonus up to
    $2,000 AUD, along with 100 free spins. Boasting a vast selection of thrilling pokies, classic table games, and immersive
    live dealer experiences, Level Up offers an unparalleled entertainment experience.

    References:
    https://blackcoin.co/nine-casino-premium-gaming-destination-for-australia/

  7. Over 500,000 expert-authored dictionary and thesaurus entries
    Browse related words to learn more about word associations.
    There are still about 200 people working during decommissioning so it remains an important
    employer but well short of the numbers it once had.

    Examples are provided to illustrate real-world usage of words in context.
    In some cases, collection is authorised or required by law, and consent is not
    required. Where required, TSEG relies on consent through clear
    signage and Conditions of Entry.
    Important means something has high value, strong impact, or special priority.
    Learning other words for important helps you match the
    meaning to the situation. Sometimes a thing matters because
    it affects your future. French-English dictionary, translator, and
    learning Spanish-English dictionary, translator, and learning
    These fit lessons, exams, rules, and study goals. Matching strength to the situation keeps your meaning natural.
    These show importance because the matter
    is serious, risky, or time sensitive. These show importance
    because something has strong meaning or effect.

    References:
    https://blackcoin.co/top-online-casinos-and-games-in-new-zealand/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>