title: configuring hibernate datasource in spring xml
body: <p>I get below error while running my web application. I had problems in configuring hibernate &amp; spring with right jars. After i crossed that hurdle after working on it for hours, i am getting problem in <strong>hibernate datasource</strong>.  The session factory and dao beans are getting initialized properly by spring 
  but when i access method in dao i get error...</p>
  
  <pre><code>    INFO:   Attestation_spring_hibernate was successfully deployed in 11,309 milliseconds.
  INFO:   before calling rateDAO.getCount()
  INFO:   inside getSessionFactory()
  WARNING:   StandardWrapperValve[dispatcher]: Servlet.service() for servlet dispatcher threw exception
  java.lang.UnsupportedOperationException: Not supported by BasicDataSource
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1062)
      at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
      at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:56)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:161)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159)
      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1859)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1836)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
      at org.hibernate.loader.Loader.doQuery(Loader.java:900)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
      at org.hibernate.loader.Loader.doList(Loader.java:2526)
      at org.hibernate.loader.Loader.doList(Loader.java:2512)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)
      at org.hibernate.loader.Loader.list(Loader.java:2337)
      at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:124)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1662)
      at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
      at daoImpl.RateDAO.getRateById(RateDAO.java:149)
      at controller.Controller1.welcome(Controller1.java:47)
  </code></pre>
  
  <p>Below is my <strong>application context.xml</strong>..</p>
  
  <pre><code>   &lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/test_amar"/&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value=""/&gt;
      &lt;property name="initialSize" value="2"&gt;&lt;/property&gt;    
          &lt;property name="maxActive" value="5"&gt;&lt;/property&gt;    
      &lt;property name="validationQuery" value="SELECT 1"/&gt;
    &lt;/bean&gt;
  
    &lt;!-- Hibernate Session Factory --&gt;
    &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="packagesToScan"&gt;
        &lt;array&gt;
          &lt;value&gt;entities&lt;/value&gt;
        &lt;/array&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
          &lt;/props&gt;
  
      &lt;/property&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>i use <strong>spring3 &amp; hibernate4</strong>. It appears there is configuration error in my datasource. but i am not able to locate it.</p>
  
  <p>From the server log below , i see that dao &amp; session factory beans are instantiated properly. </p>
  
  <pre><code>INFO:   Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
  INFO:   JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
  INFO:   JSR-330 'javax.inject.Named' annotation found and supported for component scanning
  INFO:   JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
  INFO:   Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1020cb7: defining beans [**controller1,rateDAO**,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,urlMapping,viewResolver,indexController,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@fca094
  INFO:   Mapped URL path [/controller1] onto handler 'controller1'
  INFO:   Mapped URL path [/controller1/*] onto handler 'controller1'
  </code></pre>
  
  <p>Kindly assist..</p>