Transaction Propagation and Isolation in Spring @Transactional 1. Introduction In this tutorial, we’ll cover the @Transactional annotation and its isolation and propagation settings. 2. What Is @Transactional? We can use @Transactional to wrap a method in a database transaction. It allows us to set propagation, isolation, timeout, read-only, and rollback conditions… Continue Reading spring-transactional-propagation-isolation

Transaction Support in Spring Integration 1. Overview In this tutorial, we’ll take a look at transaction support in the Spring Integration framework. 2. Transactions in Message Flows Spring provides support for synchronizing resources with transactions since the earliest versions. We often use it to synchronize transactions managed by multiple transaction… Continue Reading spring-integration-transaction

Programmatic Transaction Management in Spring 1. Overview Spring’s @Transactional annotation provides a nice declarative API to mark transactional boundaries. Behind the scenes, an aspect takes care of creating and maintaining transactions as they are defined in each occurrence of the @Transactional annotation. This approach makes it easy to decouple our… Continue Reading spring-programmatic-transaction-management

A Guide to Spring’s Open Session In View 1. Overview Session per request is a transactional pattern to tie the persistence session and request life-cycles together. Not surprisingly, Spring comes with its own implementation of this pattern, named OpenSessionInViewInterceptor, to facilitate working with lazy associations and therefore, improving developer productivity. In… Continue Reading spring-open-session-in-view

TransactionRequiredException Error 1. Overview In this tutorial, we’re going to examine the cause of the TransactionRequiredException error and how to solve it. 2. TransactionRequiredException This error typically occurs when we’re trying to perform a database operation that modifies the database without a transaction. For example, attempting to update a record… Continue Reading jpa-transaction-required-exception

Programmatic Transactions in the Spring TestContext Framework 1. Introduction Spring has excellent support for declarative transaction management throughout application code as well as in integration tests. However, we may occasionally need fine-grained control over transaction boundaries. In this article, we’ll see how to programmatically interact with automatic transactions set up… Continue Reading spring-test-programmatic-transactions

Transactions with Spring and JPA 1. Overview This tutorial will discuss the right way to configure Spring Transactions, how to use the @Transactional annotation and common pitfalls. For a more in-depth discussion on the core persistence configuration, check out the Spring with JPA tutorial. Basically, there are two distinct ways… Continue Reading transaction-configuration-with-jpa-and-spring

A Guide to Transactions Across Microservices 1. Introduction In this article, we’ll discuss options to implement a transaction across microservices. We’ll also check out some alternatives to transactions in a distributed microservice scenario. 2. Avoiding Transactions Across Microservices A distributed transaction is a very complex process with a lot of… Continue Reading transactions-across-microservices

Spring Data MongoDB Transactions 1. Overview Starting from the 4.0 release, MongoDB supports multi-document ACID transactions. And, Spring Data Lovelace now provides support for these native MongoDB transactions. In this tutorial, we’ll discuss Spring Data MongoDB support for synchronous and reactive transactions. We’ll also take a look at Spring Data TransactionTemplate for… Continue Reading spring-data-mongodb-transactions

Enabling Transaction Locks in Spring Data JPA 1. Overview In this quick tutorial, we’ll discuss enabling transaction locks in Spring Data JPA for custom query methods and predefined repository CRUD methods. We will also have a look at different lock types and setting transaction lock timeouts. 2. Lock Types JPA… Continue Reading java-jpa-transaction-locks