title: Unable to acquire JDBC Connection
body: <p>I have a Spring Boot project with Hibernate and Hikari DataSource.
  If i have some functionality with injected SessionFactory object to get session object, in few days I have such exception for any methods assosiated with db operations (only restarting solves this problem):</p>
  
  <pre><code>org.springframework.transaction.CannotCreateTransactionException: 
  Could not open JPA EntityManager for transaction; nested exception is 
  javax.persistence.PersistenceException: 
  org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection at
  ......
  Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - 
  Connection is not available, request timed out after 30001ms.
  </code></pre>
  
  <p>It seems to manual used session makes this problem. (I have similar project with the same configs and functionality, but without injected SessionFactory and Session...and I don't have such problem at all)</p>
  
  <p><strong>application.yaml</strong>:</p>
  
  <pre><code>spring:
    jpa:
      properties:
        hibernate:
          dialect : org.hibernate.dialect.PostgreSQLDialect
          current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
  </code></pre>
  
  <p><strong>DataSourceConfig</strong></p>
  
  <pre><code>@EnableJpaRepositories("com.my.project.config")
  @Configuration
  public class DataSourceConfig {
  
      @Inject
      private AppProperties properties;
  
      @Bean(name = "dataSource")
      public DataSource dataSource() {
          AppProperties.DatabaseProperties dbProps = properties.getDatabaseProperties();
          HikariDataSource dataSource = new HikariDataSource();
          dataSource.setDriverClassName(org.postgresql.Driver.class.getName());
          dataSource.setJdbcUrl(
              dbProps.getProtocol().concat("://")
                  .concat(dbProps.getDbHost()).concat(":")
                  .concat(dbProps.getDbPort()).concat("/")
                  .concat(dbProps.getDbname())
          );
          dataSource.setUsername(dbProps.getUsername());
          dataSource.setPassword(dbProps.getPassword());
          dataSource.setMaximumPoolSize(30);
          dataSource.setMinimumIdle(30);
  
          return dataSource;
      }
  
      @Bean
      public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf)   {
          return hemf.getSessionFactory();
      }
  }
  </code></pre>
  
  <p><strong>LogRepositoryImpl</strong></p>
  
  <pre><code>@Repository
  public class LogRepositoryImpl implements LogRepository {
  
      @Autowired
      private SessionFactory sessionFactory;
  
      @Override
      public List&lt;Log&gt; getLogs(int offset, int count) {
          Criteria criteria = getSession().createCriteria(Log.class);
          return criteria.setFirstResult(offset).setMaxResults(count).list();
      }
  
      @Override
      public void save(Log log) {
          getSession().save(log);
      }
  
      private Session getSession() {
          return sessionFactory.getCurrentSession();
      }
  }
  </code></pre>
  
  <p>dataSource.setMaximumPoolSize(30),
          dataSource.setMinimumIdle(); didn't solve this problem</p>