• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
8 views

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)  

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:

https://github.com/robertoschwald/grails-audit-logging-plugin/issues/175

by (21.9k points)  
edited by
...