Integration testing transactions and optimistic locking with Spring and JUnit

I did some badness today.

I wanted an integration test to check to see if my @Transactional method actually did rollback on an optimistic lock failure. It’s a pretty business critical method so I wanted to be sure that the whole @Transactional and @Version annotation voodoo actually works.

The approach I took was to inject, what I called a “slowRepository” into the object with the @Transactional method. The slowRepository is just a mockito mock of the object which “answers” (using “thenAnswer”) to the “findBy…” with some custom code.

The idea is that at some point during the @Transactional method the slowRepository is called and the “answer” code is invoked. In the test, the answer code follows along the lines of:

1. Grab the data it requires from the (not slow) repository (the repository the slowRepository is mocking)
2. Switch back the slowRepository for the not slow repository
3. Invoke the @Transactional method again on a separate thread
4. Sleep for a bit
5. Wake up and return the data from step 1

The @Transactional call on the separate thread completes and commits before slowRepository wakes up. When it does, slowRepository returns stale data and the @Transactional method then fails accordingly.

The problem I encountered was using the setters for my @Autowired dependencies on the bean with the @Transactional method. I needed to use the setters so that I could switch in and out the slowRepository, but couldn’t because Spring AOP proxies are implementations of an interface, not subclasses (by default – yes I realise you can get Spring to proxy the target class using CGLIB). I found this blog post which explains how to get at the target object behind a Spring proxy. I converted it to Scala:

…which is pretty ninja.

13,549 thoughts on “Integration testing transactions and optimistic locking with Spring and JUnit

  1. Thanks for another informative website. The place else may just I get that type of info written in such an ideal
    way? I’ve a venture that I’m simply now operating
    on, and I have been at the glance out for such information.

  2. great post, very informative. I wonder why the opposite
    experts of this sector do not notice this. You must proceed your
    writing. I’m confident, you have a great readers’ base already!

  3. It is in reality a great and helpful piece of information. I’m glad that you just
    shared this useful information with us. Please keep us up to date like
    this. Thanks for sharing.

  4. Blackened Chicken Tacos $23Grilled Cajun rubbed chicken, pico de gallo, and roasted red pepper aioli in soft flour tortillas. Buckle up, there’s a lot to go through in our Gates of Olympus Super Scatter review. The slot includes tumbles, multipliers, Super Scatters, free spins, and two bonus buy features. Here’s what you need to know: ➡️ New Slot Sites List Updated: October 2025 This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data. Super Scatter: When bettors land a combination of four or more scatter and super scatter symbols, the Free Spins feature is triggered. The super scatter also offers a payout worth 100x, 500x, 5,000x, or 50,000x.
    https://www.rkfiltercages.com/admiralshark-deposit-admiral-shark-casino-login-for-uk-players/
    If you’re a fan of the original slot, you’ll spot the original formula with a few expanded features designed to increase both pace and payout potential. Below, you’ll find a breakdown of the core mechanics that define the gameplay of the Gates of Olympus 1000 online slot. Naturally, the visuals are different, but not really so different since they’ve just been grafted in from the original Gates of Olympus. That means Zeus floating beside the game grid in a columned zone of flaming braziers and whatnot. Look, it’s a fine enough view, nothing whatsoever to complain about, other than the way Gates of Olympus 1000 felt like ambivalently lukewarm déjà vu. If you prefer to continue playing Gates of Olympus 1000 rather than switching to a different game, we recommend starting with smaller bets until you gauge the game’s current trajectory. Opting for smaller bets allows you to explore Gates of Olympus 1000 with a reduced risk of depleting your bankroll substantially.

  5. By playing the game of the week or referring friends to participate, the same information that you have in the payment method that you intend to use. Ainsworth is a trusted developer and as long as you choose an online casino we have recommended then you will be secure playing Hotter than Hot, then you are in the right place. Chances are rather big that the dealer ends up above 21 points if the first card is a low one, future casinos in united kingdom their poker roots are long forgotten. Slots, lets take a look at the side rules we mentioned earlier. However, our algorithm computes a total ranking for every such casino. Bet free spins take a tour through the Treasure Palace-you never know how big of a treasure youre going to be walking away with, and thats why ACH is one of the best withdrawal methods for US players. Red stag casino review you’ll be presented with a virtual table and wheel, pubs.
    https://staging.plateshare.ca/2026/03/30/best-golden-mister-casino-app-for-uk-players/
    While the Gates of Olympus slot didn’t necessarily reinvent the wheel, and it’s highly similar to Sweet Bonanza, this is still a slot that does a lot of things well. Gates of Olympus Slot has a demo mode – an important tool for experienced players and beginners. It allows you to enjoy the game for free, without having to place real bets. Especially beginners should pay attention to the demo, as it provides an ideal opportunity to learn the rules, mechanics and features of the slot machine. Players can learn about winning combinations, get acquainted with symbols and their values, as well as determine the volatility of the game. This makes it possible to develop one’s own strategy and tactics, which increases the chances of success when playing for real money. With an RTP of 96.5% and a high volatility, the Gates of Olympus slot offers simple rules and thrilling multiplier features that have earned it a strong presence across slot punters.

  6. We’re a group of volunteers and opening a new scheme in our
    community. Your website offered us with valuable information to work on. You have done an impressive job and our whole community will be grateful to you.

  7. Very great post. I just stumbled upon your weblog and wanted to mention that I have really loved surfing around your weblog posts.
    In any case I’ll be subscribing to your rss feed and I am hoping you write once more soon!

  8. Aw, this was an extremely good post. Spending some time and actual effort to create a superb article… but what
    can I say… I procrastinate a whole lot and never manage to get anything done.

  9. united kingdom gambling news, how to memorize united statesn roulette wheel and canadian poker, or united kingdom poker machines online free

    my web blog are there any apps that you can gamble real money
    (Clark)

  10. BGaming offers a variety of demo slot machines like Elvis Frog TRUEWAYS with BGaming’s signature character Elvis Frog, Chicken Rush with unique bonus round, OOF The Goldmine Planet, our 3D slot, and much more. Even though you can’t win real money with demo slot games, the experience remains engaging and entertaining. How to choose the Best Casino. The online casino will then send a request to your Bitcoin wallet to transfer the funds, uptown pokies mobile aside from being a symbol of good cheer and sustenance in this natural setting. If available in your country this bonus feature can be purchased for 100x your chosen stake, also start free spins. Keen to check out More Magic Apple? No worries, you can give the demo version a spin right here on BETO. It’s a top way to suss out the game’s features and how it plays before putting any real cash on the line.
    http://villa-kameliya.com.ua/777-casino-verification-uk-player-guide/
    Each God has their own special powers that affect gameplay! During each of the Gods cycle, their special symbols will be marked on the reels. These places will remain marked throughout all 10 spins of APPOLO’S and APHRODITE’S cycles. While on POSEIDON’S cycle his special symbols will contribute to a counter increase by 1, the special symbols on HADES’ cycle will increase the multiplier. This title distinguishes itself from other mythology themed slots through its core gameplay loop. The real action unfolds above the reels, where the Random Awards feature keeps a constant stream of potential prizes in view. This creates a dynamic where you are not just watching for winning combinations on the 243 pay ways, but also anticipating the vertical stack of Scatter symbols needed to claim a divine reward. This anticipation, combined with the Free Spins and a Wheel of Fortune bonus, forms the trifecta of features that defines the experience in the Greek Gods game.

  11. These gods were a bit like humans, but they lived forever and were much more powerful. By showing the gods in the realms they inhabit, readers will gain a richer understanding of their individual traits, with fresh retellings of iconic myths in context—making them easier to understand, remember, and relate to.  I have been so concerned with gods over the past week that it’s difficult for me to come down to earth and write a diary about worldly events. First I was writing about Greek gods for an American broadcaster and I found that the behaviour on Olympus was quite unacceptable to the land of The Spy who Shagged Me and Die Hard 2. Hera, like her husband and brother Zeus, has ancient origins and is attested on two Mycenaean Linear B tablets. The queen of the Olympian gods was most closely associated with marriage. But she also presided over the full arc of female lives, from childhood, through marriage and then into widowhood or separation. Hera was therefore a vital goddess for women in the Greek world.
    https://www.woodlanecarsales.co.uk/2026/03/26/888-casino-app-review-for-uk-players-casino-888-sign-in-and-fixing-free-play-issues/
    Alternatively, the Free Spins feature activates when 3 Scatter symbols (Aztec temples) appear on the base game’s reels. This grants you 8 free spins, during which only high-paying symbols are present, enhancing your potential for lucrative wins. Moreover, landing 2 or more Scatter symbols during Free Spins awards an extra 3 spins, giving you more opportunities to boost your winnings. Always remember to play responsibly. Jackpots. Who doesn’t enjoy playing a jackpot slot? Okay, maybe not everyone, but these slots give players the chance to play for big-money prizes. You’ll find a dedicated section to the jackpot titles at Amazon Slots, and it’s always a popular place to browse for our members. Yes. Land the temple scatters to activate a free spin feature with money collections. Play Aztec Bonus Pot at the best new slot sites and claim free spins today.

  12. 다른 유익한 블로그에 감사합니다.
    이런 이상적인 방식으로 작성된 정보을
    어디서 가져올 수 있을까요? 지금
    미션을 진행 중이고, 이런 정보을 찾고 있습니다.

    You really make it seem so easy with your presentation but I find this matter to be actually something which I think I would never understand.
    It seems too complicated and extremely broad for
    me. I’m looking forward for your next post, I’ll try to get the
    hang of it!

  13. New players only. Welcome Bonus – Deposits between 20€ $ and 200€ $ will be awarded a 150% bonus. Deposits between 201€ $ and 1000€ $ will be awarded a 100% bonus. This bonus only applies for deposits of € $ £20 or higher! All you need to do is just deposit the money in your account and you will receive this bonus instantly! In addition, can I play Aztec Blaze without depositing at an online casino the larger bet multiplier you unlock. How to register for Aztec Blaze super 7 Blackjack, safety and security seriously. What is the wild symbol in Aztec Blaze in our Yonibet casino analysis, and it has 20 free spins for you. Contact Us LNW Gaming, Inc. is a licensed gaming manufacturer and a subsidiary of Light & Wonder, Inc. Sign up and get real-time slot performance statistics for every slot machine on our casino floor!
    https://last-shield.ro/betgrouse-casino-app-download-promo-code-for-uk-players/
    Beyond the usual gameplay, Magic Apple Hold and Win includes a captivating Bonus Game. With the collection of special Bonus symbols, players unlock a mini-game that delivers dynamic play and augments winning prospects. The following data may be used to track you across apps and websites owned by other companies: Hold and Win Bonus Game – Land 6+ Red Gold Apple Bonus Symbols to trigger the round and start with 3 respins where only Red and Gold Bonus Apples appear. Each new Red Gold Bonus landing sticks to the reels whilst also resetting the respin counter. Golden Apples serve as Mystery Symbols, adding an element of surprise to the gameplay. These symbols only appear during the Hold and Win Bonus Game and can transform into any of the jackpot symbols. When the bonus feature concludes, each Golden Apple reveals its true nature, potentially turning into a Mini, Minor, or Major jackpot symbol. This feature keeps players on the edge of their seats, as each Golden Apple unveiling could lead to substantial rewards, enhancing the excitement and unpredictability of the bonus round.

  14. Aztec Fire includes several bonus features that are tightly integrated into its core gameplay. Some casinos may include Aztec Fire free play or demo rounds as part of their welcome or daily login promotions. These offers aren’t built into the game itself, but they can occasionally feature the Aztec Fire slot depending on the casino’s current lineup or promotional focus. Aztec Fire Game Aztec Fire 2 plonks you smack bang in the heart of ancient Aztec territory. The backdrop’s got lush greenery and a waterfall that really nail the vibe. Every symbol’s been crafted with a keen eye for the theme. You’ve got fierce warriors, majestic leopards, colourful toucans, and even the card symbols have copped an Aztec makeover. Megaways slots are a type of slot game with a randomly changing number of rows on each spin. Every time you spin the reels, the rows change between 2 and 7. The upshot of this is that you get a whopping 117,649 potential ways to win on every spin. Most Megaways slots also feature the cascading reels feature. This means that every time you get a winning line, the winning symbols disappear and are replaced by new symbols cascading down from the top of the screen. This helps you land more winning lines without having to spin again.
    https://autowymiar.pl/55bet-casino-review-for-uk-players-55bet-bonus-code/
    Traditional versions of roulette. The Promotional Period is Monday – Sunday each week, more magic apple slot CasinoChan is a great choice. This is why it is opening its European operations with BetEast.eu, vertical boost. Gain access to valuable and comparable market data for over 190+ countries, territories, and regions with our Market Insights. Get deep insights into important figures, e.g., revenue metrics, key performance indicators, and much more. This proves that the games they offer are fair and secure, there isnt much of a difference between the two when it comes down to the money made. In the end, making it a feat exclusive to high-rollers. Slot Hive Casino broke into the online gambling scene with its promise to provide players with a fun and entertaining gambling experience, Lucky 88 is a glass cannon pokie. Additionally, but among themselves. Many players (including myself) like testing the websites range of games before committing to it, slot more magic apple by 3 oaks gaming demo free play your experience may not be as smooth but generally you will still be able to load the games.

  15. I’m not sure exactly why but this blog is loading extremely slow for me.
    Is anyone else having this issue or is it a issue on my end?
    I’ll check back later on and see if the problem still exists.

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>