There is an application with MySQL, Hibernate and HicariCP combo for interaction with database using JTA session management paradigm. Application running using WildFly application server. Configuration looks like following
@Configuration
@EnableTransactionManagement
@ComponentScan("XXX")
public class DatabaseConfig {
@Bean
public LocalSessionFactoryBean sessionFactory(CustomDatasource datasource) {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(datasource);
sessionFactory.setPackagesToScan("XXX");
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory);
return transactionManager;
}
@Bean
public DefaultMergeEventListener mergeEventListener() {
return new DefaultMergeEventListener();
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.current_session_context_class", "jta");
properties.put("hibernate.transaction.factory_class", "org.hibernate.transaction.JTATransactionFactory");
properties.put("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.JBossTransactionManagerLookup");
properties.put("hibernate.transaction.jta.platform", "JBossAS");
return properties;
}
}
After upgrading Hibernate from 3.6.10.Final to 5.1.17.Final we noticed that number of connections retrieved from connection pool considerably increased. For verification purposes we've added a counter on how many times javax.sql.Datasource.getConnection() is executed.
We executed certain business flow which involves multiple APIs and compared results before and after upgrade. And it's interesting that number of connections acquired per API is exactly doubled.
In terms of what have changed - just dependency version upgrade, updated several hibernate classes packages and added @Transactional annotation to Dao/Repository level. Nothing else.
Wondering what have changed internally within Hibernate which caused this difference? Appreciate any help!