Spring MVC Hibernate No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
<p>I want to make a POST request to save a user into my Oracle DB.</p>

<p>I'm using Spring MVC with jpa and hibernate.</p>

<p>Here is my <strong>jpaContext.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"&gt;

    &lt;context:annotation-config /&gt;   
    &lt;context:component-scan base-package="com.licenta.ascourses" /&gt;

     &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;    

    &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
        &lt;property name="persistenceUnitName" value="punit" /&gt;
        &lt;property name="dataSource" ref="dataSource" /&gt;
        &lt;property name="jpaVendorAdapter"&gt;
            &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                &lt;property name="showSql" value="true" /&gt;
            &lt;/bean&gt;             
        &lt;/property&gt;
        &lt;property name="jpaPropertyMap"&gt;
            &lt;map&gt; 
                &lt;entry key="hibernate.dialect"      value="org.hibernate.dialect.Oracle8iDialect" /&gt;
                &lt;entry key="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
                &lt;entry key="hibernate.format_sql"   value="true" /&gt;
            &lt;/map&gt;
        &lt;/property&gt;
    &lt;/bean&gt; 

    &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
        &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
    &lt;/bean&gt; 

    &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

    &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
        &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
        &lt;property name="url"             value="jdbc:oracle:thin:@localhost:oracle" /&gt;
        &lt;property name="username"        value="user" /&gt;
        &lt;property name="password"        value="pass" /&gt;
    &lt;/bean&gt;

&lt;/beans&gt;
</code></pre>

<p>Here is my UserRepoImpl class:</p>

<pre><code>package com.licenta.ascourses.repositories.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.licenta.ascourses.model.User;
import com.licenta.ascourses.repositories.UserRepo;

@Repository("userRepository")
public class JpaUserRepo implements UserRepo {

    @PersistenceContext(type=PersistenceContextType.EXTENDED)
    private EntityManager em;

    public User getUserById(Long id) {
        return em.find (User.class, id);
    }

    public List&lt;User&gt; getAllUsers() {
        return null;
    }

    public User createUser(User user) {
        em.persist(user);
        em.flush();

        return user;
    }
}
</code></pre>

<p>And this is the UserServiceImpl class:</p>

<pre><code>package com.licenta.ascourses.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.licenta.ascourses.model.User;
import com.licenta.ascourses.repositories.UserRepo;
import com.licenta.ascourses.repositories.jpa.JpaUserRepo;


@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepo userRepo;

    public User getUserById(Long id) {
        return userRepo.getUserById(id);
    }

    public List&lt;User&gt; getAllUsers() {
        return userRepo.getAllUsers();
    }

    @Transactional
    public User createUser(User user) {
        return userRepo.createUser (user);
    }
}
</code></pre>

<p>This is the method from the REST Controller:</p>

<pre><code>@Autowired
private UserService userService;

@RequestMapping(method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_UTF8_VALUE)
public User saveUser (@RequestBody User user) {
    return userService.createUser(user);        
}         
</code></pre>

<p>I have the <code>@Transactional</code> annotation on my service layer. I've tried many solutions found online, using @Transactional on repository layer, or use @Scope(proxyMode = ScopedProxyMode.INTERFACES) to repository or service classes. Nothing worked for me.
I'm a newbie to Spring and Hibernate so all answers or suggestions are well welcomed</p>

<p>This is the exception I get when try to make a POST:</p>

<pre><code>PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ascoursesServlet] in context with path [/ASCourses] threw exception [Request processing failed; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress] with root cause
javax.persistence.TransactionRequiredException: no transaction is in progress
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.checkTransactionNeeded(AbstractEntityManagerImpl.java:1136)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1297)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347)
    at com.sun.proxy.$Proxy24.flush(Unknown Source)
    at com.licenta.ascourses.repositories.jpa.JpaUserRepo.createUser(JpaUserRepo.java:32)
    at com.licenta.ascourses.service.UserServiceImpl.createUser(UserServiceImpl.java:33)
    at com.licenta.ascourses.controller.TestController.saveUser(TestController.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:785)
</code></pre>