0

We have configured our spring boot(v1.5.1)-jpa application to point to HikariCP but still due to some weird reason the application is still pointing to tomcat-jdbc pool, the default used by spring-boot instead of Hikari-CP. I have mentioned the configuration used below.

Updates
After making changes now when the HikariCP is trying to load we are getting the SQLNotSupportedFeature Exception. Do note that we are using Springboot-JPA-Hibernate combination along with hikari.

Any help is appreciated.

Gradle

    // https://mvnrepository.com/artifact/com.zaxxer/HikariCP
    compile group: 'com.zaxxer', name: 'HikariCP', version: '2.3.2'

    // Exclusions
    compile('org.springframework.boot:spring-boot-starter-web'){
    exclude module: "spring-boot-starter-tomcat"
    }
    compile('org.springframework.boot:spring-boot-starter-data-jpa') {
    exclude module: "spring-boot-starter-tomcat"
    }
    compile("org.springframework.boot:spring-boot-starter-jdbc") {
    exclude module: "spring-boot-starter-tomcat"
    }
    //spring integration
    compile("org.springframework.boot:spring-boot-starter-integration"){
    exclude module: "spring-boot-starter-tomcat"
    }  

application.properties

hibernate.show.sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.datasource.hikari.maximum-pool-size=50
spring.datasource.hikari.idle-timeout=1000
spring.datasource.hikari.pool-name=pooool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource

spring.datasource.url=jdbc:oracle:thin:@<hostname>:1521/<instance>
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

Dataconfiguration

We are using Spring JPA hibernate combination for configuration along with PCF (Pivotal Cloud Foundry).

        public class DataSourceConfiguration {

            @Value("${spring.datasource.hikari.maximum-pool-size}")
            private int maxSize;

            @Value("${spring.datasource.hikari.idle-timeout}")
            private String idleTimeout;

            @Value("${spring.datasource.username}")
            private String username;

            @Value("${spring.datasource.password}")
            private String password;

            @Value("${spring.datasource.url}")
            private String url;

            @Value("${spring.datasource.driver-class-name}")
            private String driverClassName;

            @Bean("destroyMethod=close")
            @Primary
            public DataSource dataSource() {
                HikariDataSource dataSource = new HikariDataSource();
                dataSource.setUrl(url);
                dataSource.setPassword(password);
                dataSource.setUsername(username);
                dataSource.setDriverClassName(driverClassName);
                dataSource.setValidationQuery(idleTimeout);
                dataSource.setMaxIdle(maxSize);
                return dataSource;
            }

            @Bean
            public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
                System.err.println("POOLSIZE----> " +dataSource.getPoolSize());
                System.err.println("POOLNAME----> " +dataSource.getName());
                    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
                    entityManagerFactoryBean.setDataSource(dataSource);
                    entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
                    entityManagerFactoryBean.setPackagesToScan(applicationPropertiesConfig.getPackagestoScan());

                    Properties jpaProperties = new Properties();
                    jpaProperties.put("hibernate.dialect", applicationPropertiesConfig.getHibernateDialect());
                    jpaProperties.put("hibernate.show_sql", applicationPropertiesConfig.getHibernateShowSQL());
                    entityManagerFactoryBean.setJpaProperties(jpaProperties);
                    return entityManagerFactoryBean;
            }

            /**
             * Declaration of the transaction manager.
             *
             * @param entityManagerFactory the entity manager factory
             * @return an instance of JpaTransactionManager
             */
            @Bean
            JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
                    JpaTransactionManager transactionManager = new JpaTransactionManager();
                    transactionManager.setEntityManagerFactory(entityManagerFactory);
                    return transactionManager;
            }

Please help as this is blocking our application and is frustrating. Thanks in advance.

Gururaj Nayak
  • 636
  • 1
  • 9
  • 18
  • I am assuming you have Hikari-CP in your dependencies correct? Make sure you expelicitly exclude tomcat-jdbc from the POM. https://www.mkyong.com/spring-boot/spring-boot-jdbc-mysql-hikaricp-example/ –  Jun 30 '17 at 13:59
  • sorry i forgot to mention it earlier. yes we did add exclusions but it is of no use. – Gururaj Nayak Jun 30 '17 at 15:16
  • After comparing your project with one of my own that I know is working with HikaryCP. The only different I see is that you do not have a driver in the pom. Maybe that is not being picked up. Try adding this dependency compile group: 'oracle', name: 'ojdbc6', version: '11.2.0.3' –  Jun 30 '17 at 15:37
  • Thanks will try this and let you know. We also suspected this since we are getting the SqlNotsuppoertedFeature Exception when hikari is trying to load itself – Gururaj Nayak Jun 30 '17 at 16:10
  • what's your Hibernate version? – Ori Marko Jul 06 '17 at 08:24
  • We are using hibernate 5.0+ version jars along with spring boot starter jpa as a wrapper – Gururaj Nayak Jul 07 '17 at 13:00

2 Answers2

0

You should new HikariDataSource(.....) instead of new DataSource() in your bean.

Liping Huang
  • 4,378
  • 4
  • 29
  • 46
  • Thanks for your response. However if i do that will it not be "hard coding". I want to keep my code flexible. Say tomorrow if we want to switch from Hikari to Tomcat or some-other pool i expect to change only the config files without touching the code. We will also lose the advantage of {spring.datasource.type} that is provided by spring. According to documentation just mentioning the type and configuring the properties is enough. is this a bug faced by all ? – Gururaj Nayak Jun 30 '17 at 15:18
  • So it is better to add your requirements in your question. And maybe replace the pool is really not a real requirement. – Liping Huang Jun 30 '17 at 23:15
  • we tried your suggestion, however we are getting the SQLFeatureNotSupportedException we tried the oracle driver name: 'ojdbc6', version: '11.2.0.3', ojdbc7 etc but still keep getting the same error – Gururaj Nayak Jul 01 '17 at 11:56
0

Your gradle should have following config for hikari:

configurations {
     compile.exclude module: "tomcat-jdbc"
}

dependencies {
     compile("org.springframework.boot:spring-boot-starter-jdbc")
     compile group: 'com.zaxxer', name: 'HikariCP', version: '2.6.3'
}

Above will exclude tomcat-jdbc and will create connection pool using hikari. Hope this will help.

Programmer
  • 325
  • 5
  • 18