Questions tagged [spring-transactions]

Questions related to Spring's Transaction API (programmatic or declarative)

Comprehensive transaction support is among the most compelling reasons to use the Spring Framework. It provides a consistent abstraction for transaction management that delivers the following benefits:

  • Consistent programming model across different transaction APIs such as Java Transaction API (JTA), JDBC,
  • Hibernate, Java Persistence API (JPA), and Java Data Objects (JDO).
  • Support for declarative transaction management.
  • Simpler API for programmatic transaction management than complex transaction APIs such as JTA.
  • Excellent integration with Spring's data access abstractions.

Guides:

Video tutorial on Spring Framework

Blog:

Related tags

1985 questions
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
117
votes
4 answers

What is the difference between defining @Transactional on class vs method

Case1 @Transactional public class UserServiceImpl implements UserService { ................... public void method1(){ try{ method2(); }catch(Exception e){ } } public void method2(){ …
Anil Kumar
  • 1,431
  • 3
  • 13
  • 14
83
votes
3 answers

How to manually force a commit in a @Transactional method?

I'm using Spring / Spring-data-JPA and find myself needing to manually force a commit in a unit test. My use case is that I am doing a multi-threaded test in which I have to use data that is persisted before the threads are spawned. Unfortunately,…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
74
votes
5 answers

Synchronising transactions between database and Kafka producer

We have a micro-services architecture, with Kafka used as the communication mechanism between the services. Some of the services have their own databases. Say the user makes a call to Service A, which should result in a record (or set of records)…
74
votes
2 answers

Spring - Is it possible to use multiple transaction managers in the same application?

I'm new to Spring and I'm wondering if its possible to use numerous transaction managers in the same application? I have two data access layers - one for both of the databases. I'm wondering, how do you go about using one transaction managers for…
Brian DiCasa
  • 9,369
  • 18
  • 65
  • 97
72
votes
2 answers

Spring transaction REQUIRED vs REQUIRES_NEW : Rollback Transaction

I have a method that has the propagation = Propagation.REQUIRES_NEW transactional property: @Transactional(propagation = Propagation.REQUIRES_NEW) public void createUser(final UserBean userBean) { //Some logic here that requires modification in…
Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
45
votes
9 answers

The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

I am trying to configure JSF+Spring+hibernate and I'm tying to run a test but when I use this "tx:annotation-driven" on my application-context.xml file, I get this error: The matching wildcard is strict, but no declaration can be found for element…
cascadox
  • 893
  • 4
  • 14
  • 32
43
votes
6 answers

Spring nested transactions

In my Spring Boot project I have implemented following service method: @Transactional public boolean validateBoard(Board board) { boolean result = false; if (inProgress(board)) { if (!canPlayWithCurrentBoard(board)) { …
alexanoid
  • 24,051
  • 54
  • 210
  • 410
41
votes
1 answer

Spring JPA repository transactionality

1 quick question on Spring JPA repositories transactionality. I have a service that is not marked as transactional and calls Spring JPA repository method userRegistrationRepository.deleteByEmail(email); And it is defined as @Repository public…
FlasH from Ru
  • 1,165
  • 2
  • 13
  • 19
37
votes
1 answer

Why do spring/hibernate read-only database transactions run slower than read-write?

I've been doing some research around the performance of read-only versus read-write database transactions. The MySQL server is remote across a slow VPN link so it's easy for me to see differences between the transaction types. This is with…
Gray
  • 115,027
  • 24
  • 293
  • 354
33
votes
8 answers

How to set autocommit to false in spring jdbc template

Currently I'm setting autocommit to false in spring through adding a property to a datasource bean id like below : But i need to add it specifically in a single java method before executing my…
bad programmer
  • 331
  • 1
  • 3
  • 4
23
votes
1 answer

Spring Transactions and hibernate.current_session_context_class

I have a Spring 3.2 application that uses Hibernate 4 and Spring Transactions. All the methods were working great and I could access correctly the database to save or retrieve entities. Then, I introduced some multithreading, and since each thread…
user1781028
  • 1,478
  • 4
  • 22
  • 45
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
1 answer

What are advantages of using @Transactional(readOnly = true)?

I am beginner and as I understand @Transactional simply make sure that all the internal work of a class or method annotated with @Transactional will be wrapped in one transaction and all of the calls from external sources will create a new…
22
votes
7 answers

Hibernate collection is not associated with any session

I have found several questions and answers with regard to this issue on SO, but they all seem to cover one major cause of the problem: fetching a collection outside of a transaction or within another transaction. But in my case, I am fetching…
DominikM
  • 1,042
  • 3
  • 16
  • 32
1
2 3
99 100