I am using Hikari with SQL Server 2016 and sqljdbc4-2.0.jar in the tomcat lib folder.
My configuration for db resource is as follows:
<Resource name="jdbc/SQLServerDS" auth="Container" type="javax.sql.DataSource"
username="uname"
password="pwd"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://server:port;DatabaseName=dbName"
maxActive="20"
maxIdle="10"
validationQuery="select 1" />
My Datasource configuration is as follows:
@Bean(name = "dataSource")
public DataSource getDataSource() throws NamingException {
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(20);
config.setDataSourceJNDI("java:comp/env/jdbc/SQLServerDS");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("cacheResultSetMetadata", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("maintainTimeStats", "false");
return new TransactionAwareDataSourceProxy(
new LazyConnectionDataSourceProxy(new HikariDataSource(config)));
}
How do I know if the preparedstatement caching is working for different connections?
I am using spring container managed transactions with hibernate v4.3.10.Final.
Also, for the caching to work, do I need to have second-level cache enabled?