• Register
0 votes
206 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

6 5 3
6,930 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

9 7 4
38,600 points

Related questions

0 votes
2 answers 348 views
348 views
Problem : I am new to the Spring and JPA, wasted 10 days and no result with the searching on internet. I want to save the object to SQL SERVER, my connection is correct but when I write .flush() I get below exception “nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress”
asked Jan 21 jwilliam 3.9k points
0 votes
1 answer 2.2K views
2.2K views
Problem : I am getting bellow error while using hibernate JPA with spring and mongodb and running my application on Glassfish-4.0. javax.persistence.transactionrequiredexception: executing an update/delete query
asked Oct 19, 2019 peterlaw 6.9k points
1 vote
1 answer 1.3K views
1.3K views
Problem : When I try to compile my spring project, I always face the below error : Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed I have the ... >1.4.1.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> . . .
asked Dec 12, 2019 alecxe 7.5k points
0 votes
1 answer 3.8K views
3.8K views
Problem : I am developing the application in Spring, using a Tomcat, Mysql5, Java8... My problem is that I cannot deploy it, due to the "required bean 'entityManagerFactory' not found" problem. I have developed my project with the coworkers but ... a bean named 'entityManagerFactory' that could not be found. Action: Consider defining a bean named 'entityManagerFactory' in your configuration.
asked Jan 25 jwilliam 3.9k points
1 vote
1 answer 1K views
1K views
Problem : I am beginner to spring + hibernate. Recently I have created the application with the use of spring + hibernate but I always face below error. I am trying to work on it for the very first time. Below is the error for your ... ) at coreservlets.StudentDAOImpl.create(StudentDAOImpl.java:19) at coreservlets.MainApp.main(MainApp.java:14) Can somebody help me in overcoming above error?
asked Mar 28 morrisBson 3.2k points