Questions tagged [transactional]

A transaction is a collection of operations performed on a database that are supposed to execute in one unit.

A transaction is a collection of operations performed on a database that are supposed to execute in one unit. This means that in case any of the operations fails the entire transaction fails and the status of the database is rolled back to the status prior to the transaction.

Apparently this tag is only useful for databases that actually support transactions.

770 questions
544
votes
10 answers

Spring @Transactional - isolation, propagation

Can someone explain what isolation & propagation parameters are for in the @Transactional annotation via real-world example? Basically when and why I should choose to change their default values.
MatBanik
  • 26,356
  • 39
  • 116
  • 178
440
votes
6 answers

Spring - @Transactional - What happens in background?

I want to know what actually happens when you annotate a method with @Transactional? Of course, I know that Spring will wrap that method in a Transaction. But, I have the following doubts: I heard that Spring creates a proxy class? Can someone…
peakit
  • 28,597
  • 27
  • 63
  • 80
139
votes
7 answers

Showing a Spring transaction in log

I configured spring with transactional support. Is there any way to log transactions just to ensure I set up everything correctly? Showing in the log is a good way to see what is happening.
cometta
  • 35,071
  • 77
  • 215
  • 324
131
votes
4 answers

@Transactional method calling another method without @Transactional anotation?

I've seen a method in a Service class that was marked as @Transactional, but it was also calling some other methods in that same class which were not marked as @Transactional. Does it mean that the call to separate methods are causing the…
goe
  • 1,311
  • 2
  • 9
  • 3
88
votes
4 answers

Why we shouldn't make a Spring MVC controller @Transactional?

There are already a few questions about the topic, but no response at all really provides arguments in order to explain why we shouldn't make a Spring MVC controller Transactional. See: Transaction not working correctly - Spring/MyBatis For web MVC…
jeromerg
  • 2,997
  • 2
  • 26
  • 36
70
votes
5 answers

Transactional saves without calling update method

I have a method annotated with @Transactional. I retrieve an object from my Oracle DB, change a field, and then return from the method. I forgot to save the object, but discovered that the database gets updated…
John LaFleur
  • 713
  • 1
  • 5
  • 5
46
votes
1 answer

How to use spring transaction in multithread

I have a method as below: ClassA.java @Transactional public void methodA(){ ExecutorService executorService = Executors.newFixedThreadPool(4); executorService.execute(new Runnable() { public void run() { …
Jacky
  • 8,619
  • 7
  • 36
  • 40
34
votes
2 answers

Why does @Transactional save automatically to database

I have a method annotated with @Transactional. I retrieve an object from my DB, change a field, and then return from the method. Without saving my object, the database gets updated anyway which is strange. Could you please tell me how to avoid this…
chidar
  • 405
  • 1
  • 5
  • 9
32
votes
1 answer

@Transactional annotation works with saveAndFlush?

I have the following implementation. @Transactional public void saveAndGenerateResult(Data data) { saveDataInTableA(data.someAmountForA); saveDataInTableB(data.someAmountForB); callAnAggregatedFunction(data); } public void…
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
28
votes
1 answer

Nested @Transactional

Is it possible to nest @Transactional annotated methods in spring? Consider something like this: @Transactional public void a() { obj.b(); } @Transactional public void b() { // ... } What happens in such a case if I rollback in b() and…
Erik
  • 11,944
  • 18
  • 87
  • 126
27
votes
1 answer

Spring Propagation examples in layman's terms

The Spring docs do a fantastic job of describing transactional propagation properties. However, I was wondering if there are any well-known, real-world examples available which describe each of these properties more thoroughly in layman's terms?
wild_nothing
  • 2,845
  • 1
  • 35
  • 47
26
votes
3 answers

Spring @Transactional inheritance rules

I have a set of @Service beans which inherit core functionality from an abstract class. I marked each of the concrete sub-class services with @Service and @Transactional. The abstract super class contains the public entry point method for each of…
DuncanKinnear
  • 4,563
  • 2
  • 34
  • 65
24
votes
4 answers

Why use @Transactional with @Service instead of with @Controller

I have seen many comments in stack-overflow articles I found certain things about either @Transactional use with @Service or with @Controller "Usually, one should put a transaction at the service layer." "The normal case would be to annotate on a…
Shahid Ghafoor
  • 2,991
  • 17
  • 68
  • 123
23
votes
1 answer

Spring @Transactional not working

I previously had a post on this issue that was resolved. However since rebuilding the project with auto wired beans and less XML configuration I find I am revisiting this issue. I have followed the way my previous project implemented this but it…
Chris Doyle
  • 10,703
  • 2
  • 23
  • 42
22
votes
4 answers

Spring @Transactional with synchronized keyword doesn't work

Let's say I have a java class with a method like this (just an example) @Transactional public synchronized void onRequest(Request request) { if (request.shouldAddBook()) { if (database.getByName(request.getBook().getName()) == null) { …
JavaDevSweden
  • 2,154
  • 2
  • 18
  • 29
1
2 3
51 52