Spring MVC & Hibernate Could not obtain transaction-synchronized Session for current thread
<p>I have Spring application which works with hibernate.The session for the hibernate is not creating.it throws error as below<br/>
[the console error][1]: <a href="http://i.stack.imgur.com/Mb0Ah.png" rel="nofollow">http://i.stack.imgur.com/Mb0Ah.png</a><br/>
My dispatcher code as below</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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
    http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-4.1.xsd"&gt;


    &lt;context:component-scan base-package="com.oi.controller" /&gt;



    &lt;bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
        &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
        &lt;property name="suffix" value=".jsp" /&gt;
    &lt;/bean&gt;

    &lt;!-- data source --&gt;
    &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        &gt;
        &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
        &lt;property name="url" value="jdbc:mysql://localhost:61391/springmvc2k" /&gt;
        &lt;property name="username" value="adminHYMgZHE" /&gt;
        &lt;property name="password" value="byIkcunaje5K" /&gt;
    &lt;/bean&gt; 

    &lt;!-- Hibernate SessionFactory --&gt;
    &lt;bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
        &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
        &lt;property name="hibernateProperties"&gt;
            &lt;props&gt;
                &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
                &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;

            &lt;/props&gt;
        &lt;/property&gt;
        &lt;property name="packagesToScan" value="com.oi.bean"&gt;&lt;/property&gt;
    &lt;/bean&gt;
    &lt;!-- The transaction manager --&gt;
    &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
    &lt;bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
        &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</code></pre>

<p>My bean class</p>

<pre><code>import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Entity;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@Entity
@Table(name="users")
public class User {
    @Id
    @GeneratedValue
    int id;
    @Column(name = "username")
    String name;
    @Column(name = "password")
    String password;
    @Column(name = "email")
    String email;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

}
</code></pre>

<p>My spring controller as follow </p>

<pre><code>import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.oi.bean.User;

@Controller
public class BaseController {
    @Autowired
    private SessionFactory sessionFactory;

    @RequestMapping(value="/")
    public String getRespnse(Model m) {
        Session session =sessionFactory.getCurrentSession();
    //  List&lt;User&gt; usrLst=(List&lt;User&gt;) session.createQuery("from User");
    //  System.out.println("IN"+usrLst);
        return "home";
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

}
</code></pre>

<p>Please help.how to proceed..!!!</p>