title: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException
body: <p>I don't find out why this error. I become more patient after googling more time with this error. It may be a database connection related issue. But I can't identify it. But the last line indicates that No suitable driver.  Please, anyone, help me.</p>
  
  <p>*In this project I have only used required jar file.</p>
  
  <pre><code>HTTP Status 500 – Internal Server Error
  
  Type Exception Report
  
  Message Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
  
  Description The server encountered an unexpected condition that prevented it from fulfilling the request.
  
  Exception
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Root Cause
  
  org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
      org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:582)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:572)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:360)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
      com.sun.proxy.$Proxy33.getCustomers(Unknown Source)
      com.luv2code.springdemo.controller.CustomerController.listCustomers(CustomerController.java:25)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:566)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Root Cause
  
  org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
      org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
      org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
      org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:107)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:134)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:259)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:267)
      org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:246)
      org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:83)
      org.hibernate.internal.AbstractSharedSessionContract.beginTransaction(AbstractSharedSessionContract.java:471)
      org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:537)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:572)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:360)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
      com.sun.proxy.$Proxy33.getCustomers(Unknown Source)
      com.luv2code.springdemo.controller.CustomerController.listCustomers(CustomerController.java:25)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:566)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Root Cause
  
  java.sql.SQLException: Connections could not be acquired from the underlying database!
      com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
      com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
      com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
      org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
      org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:38)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:104)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:134)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:259)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:267)
      org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:246)
      org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:83)
      org.hibernate.internal.AbstractSharedSessionContract.beginTransaction(AbstractSharedSessionContract.java:471)
      org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:537)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:572)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:360)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
      com.sun.proxy.$Proxy33.getCustomers(Unknown Source)
      com.luv2code.springdemo.controller.CustomerController.listCustomers(CustomerController.java:25)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:566)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Root Cause
  
  com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
      com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)
      com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
      com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
      com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
      com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
      com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
      org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
      org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:38)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:104)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:134)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:259)
      org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:267)
      org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:246)
      org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:83)
      org.hibernate.internal.AbstractSharedSessionContract.beginTransaction(AbstractSharedSessionContract.java:471)
      org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:537)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:572)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:360)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
      com.sun.proxy.$Proxy33.getCustomers(Unknown Source)
      com.luv2code.springdemo.controller.CustomerController.listCustomers(CustomerController.java:25)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:566)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  Root Cause
  
  java.sql.SQLException: No suitable driver
      java.sql/java.sql.DriverManager.getDriver(DriverManager.java:298)
      com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
      com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
      com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
      com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
      com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
      com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
      com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
      com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
      com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
      com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
  </code></pre>
  
  <p>Entity</p>
  
  <pre><code>package com.luv2code.springdemo.entity;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="customer")
  public class Customer {
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name="id")
      private int id;
  
      @Column(name="first_name")
      private String firstName;
  
      @Column(name="last_name")
      private String lastName;
  
      @Column(name="email")
      private String email;
  
      public Customer() {
  
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      @Override
      public String toString() {
          return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";
      }
  
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>package com.luv2code.springdemo.controller;
  
  import java.util.List;
  
  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 org.springframework.web.bind.annotation.SessionAttributes;
  
  import com.luv2code.springdemo.dao.CustomerDAO;
  import com.luv2code.springdemo.entity.Customer;
  
  @Controller
  @RequestMapping("/customer")
  @SessionAttributes
  public class CustomerController {
  
      // need to inject the customer dao
      @Autowired
      private CustomerDAO customerDAO;
  
      @RequestMapping("/list")
      public String listCustomers(Model theModel) {
  
          // get customers from the dao
          List&lt;Customer&gt; theCustomers = customerDAO.getCustomers();
  
          // add the customers to the model
          theModel.addAttribute("customers", theCustomers);
  
          return "list-customers";
      }
  }
  </code></pre>
  
  <p>CustomerDAO</p>
  
  <pre><code>package com.luv2code.springdemo.dao;
  
  import java.util.List;
  
  import com.luv2code.springdemo.entity.Customer;
  
  public interface CustomerDAO {
  
      public List&lt;Customer&gt; getCustomers();
  
  }
  </code></pre>
  
  <p>CustomerDAOImpl</p>
  
  <pre><code>package com.luv2code.springdemo.dao;
  
  import java.util.List; 
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.query.Query;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.luv2code.springdemo.entity.Customer;
  
  @Repository
  public class CustomerDAOImpl implements CustomerDAO {
  
      // need to inject the session factory
      @Autowired
      private SessionFactory sessionFactory;
  
      @Override
      @Transactional
      public List&lt;Customer&gt; getCustomers() {
  
          // get the current hibernate session
          Session currentSession = sessionFactory.getCurrentSession();
  
          // create a query
          Query&lt;Customer&gt; theQuery = 
                  currentSession.createQuery("from Customer", Customer.class);
  
          // execute query and get result list
          List&lt;Customer&gt; customers = theQuery.getResultList();
  
          // return the results       
          return customers;
      }
  }
  </code></pre>
  
  <p>spring-mvc-crud-demo-servlet.xml</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"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      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.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;!-- Add support for component scanning --&gt;
      &lt;context:component-scan base-package="com.luv2code.springdemo" /&gt;
  
      &lt;!-- Add support for conversion, formatting and validation support --&gt;
      &lt;mvc:annotation-driven/&gt;
  
      &lt;!-- Define Spring MVC view resolver --&gt;
      &lt;bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/view/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Step 1: Define Database DataSource / connection pool --&gt;
      &lt;bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close"&gt;
          &lt;property name="driverClass" value="com.mysql.cj.jdbc.Driver" /&gt;
          &lt;property name="jdbcUrl" value="jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&amp;amp;serverTimezone=UTC" /&gt;
          &lt;property name="user" value="springstudent" /&gt;
          &lt;property name="password" value="springstudent" /&gt; 
  
          &lt;!-- these are connection pool properties for C3P0 --&gt;
          &lt;property name="minPoolSize" value="5" /&gt;
          &lt;property name="maxPoolSize" value="20" /&gt;
          &lt;property name="maxIdleTime" value="30000" /&gt;
      &lt;/bean&gt;  
  
      &lt;!-- Step 2: Setup Hibernate session factory --&gt;
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="myDataSource" /&gt;
          &lt;property name="packagesToScan" value="com.luv2code.springdemo.entity" /&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.show_sql"&gt;true&lt;/prop&gt;
             &lt;/props&gt;
          &lt;/property&gt;
     &lt;/bean&gt;    
  
      &lt;!-- Step 3: Setup Hibernate transaction manager --&gt;
      &lt;bean id="myTransactionManager"
              class="org.springframework.orm.hibernate5.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Step 4: Enable configuration of transactional behavior based on annotations --&gt;
      &lt;tx:annotation-driven transaction-manager="myTransactionManager" /&gt;
  
      &lt;!-- Add support for reading web resources: css, images, js, etc ... --&gt;
      &lt;mvc:resources location="/resources/" mapping="/resources/**"&gt;&lt;/mvc:resources&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
    &lt;display-name&gt;spring-mvc-crud-demo&lt;/display-name&gt;
  
    &lt;absolute-ordering /&gt;
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/spring-mvc-crud-demo-servlet.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>