title: applicationContext.xml with datasource or hibernate.cfg.xml. Difference?
body: <p>Want to clear some confusion. I have applicationContext.xml.</p>
  
  <p><strong>Question 1:</strong> Whats the difference between 1 &amp; 2. Are they both same with different approach?</p>
  
  <p><strong>Question 2:</strong> </p>
  
  <p>I asked question on Spring forum regarding some problem. Onething he mentioned about pooling is below</p>
  
  <blockquote>
    <p>if you need/want to use the internal connection pooling for hibernate
    I would advice against it and simply configure a datasource which
    supports connection pooling and inject that into your
    sessionfactorybean.</p>
  </blockquote>
  
  <p><em>internal connection pooling for hibernate =</em> This is <strong>number 2 below</strong>. Right?</p>
  
  <p><em>simply configure a datasource which supports connection pooling and inject that into your sessionfactorybean =</em> This is <strong>number 1 below</strong>. right?</p>
  
  <p><strong>1# -</strong> </p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
          &lt;property name="url" value="${jdbc.url}"/&gt;
          &lt;property name="username" value="${jdbc.username}"/&gt;
          &lt;property name="password" value="${jdbc.password}"/&gt;
          &lt;property name="maxActive" value="100"/&gt;
          &lt;property name="maxIdle" value="30"/&gt;
          &lt;property name="maxWait" value="16000"/&gt;
          &lt;property name="minIdle" value="0"/&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 name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.mkyong.customer.model.Customer&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.format_sql"&gt;false&lt;/prop&gt;
                  &lt;prop key="hibernate.generate_statistics"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p><strong>2# -</strong> </p>
  
  <p>Pooling and connection info is in hibernate.cfg.xml</p>
  
  <pre><code>&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
      &lt;/bean&gt;
  </code></pre>