title: Spring+hibernate vs hibernate configuration. Cause of UnsupportedOperationException: Not supported by BasicDataSource
body: <p>Initially I used only hibernate</p>
  
  <p>And I had  following <code>hibernate.cfg.xml</code>:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;     
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/...&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;XXX&lt;/property&gt; 
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="format_sql"&gt;true&lt;/property&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;        
  
          //mapping
          ...
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>And It works good:</p>
  
  <p>after I include <em>Spring</em> and then configuration look so:</p>
  
  <pre><code>...
  &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/..." /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value=XXX /&gt; 
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
      &lt;/bean&gt;
  ...
  </code></pre>
  
  <p>after it I see in console:</p>
  
  <pre><code>java.lang.UnsupportedOperationException: Not supported by BasicDataSource
      at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1432)
      at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
  </code></pre>
  
  <p>After I tried to remove </p>
  
  <pre><code>        &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;XXX&lt;/property&gt; 
  </code></pre>
  
  <p>from <code>hibernate.cfg.xml</code> and I don't see exceptions.</p>
  
  <p>Can you explain what is the cause of this problems?</p>
  
  <p>Initially I thought that problem that I shouldn't duplicate information in different configurations but now I see that for example <code>url</code> define inside <code>dataSource</code> and inside <code>hibernate.cfg.xml</code></p>
  
  <p>Please clarify this <em>Spring + Hibernate</em> magic.</p>