Programmers learn & share
0 votes

Problem :

I am new to Spring and JPA I want to save object to SQL SERVER, connection is correct but when I write .flush() I get the exception as below

javax.persistence.TransactionRequiredException: no transaction is in progress

by (6.9k points)   | 76 views

1 Answer

0 votes

Solution :

To resolve the problem, bellow are two solutions:

1. Please avoid scanning the repository and service packages in the mvc context: this context should only care about mvc-related beans. When Spring injects a service in a controller, it would not find the service in the mvc context, and thus look it up, and find it in the main context. The transactional service would be injected.

2.Please use a single context: the one of the servlet, where all the beans in the application would be defined.

Further Readings:

by (36.1k points)  
edited by
2,227 questions
2,734 answers
241 users