Error on setting ConnectionInitSql with Hikari Version : 3.4.5

I am getting the following error when I upgrade my Hikari version to 3.4.5

The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.

I am running the following @BeforeEach test

 dataSource.getHikariPoolMXBean().softEvictConnections();
 dataSource.setConnectionInitSql("set search_path to " + getTestSchema() + ", public");

This is how I load my DataSource

public class DataSource {
  private static HikariConfig config = new HikariConfig();
  public static HikariDataSource ds;

  static {
    config.setJdbcUrl(
        System.getProperty("jdbc.url", "jdbc:postgresql://localhost:123/abc"));
    config.setUsername(System.getProperty("username", "xyz"));
    config.setPassword(System.getProperty("password", "123"));
    ds = new HikariDataSource(config);
  }

  private DataSource() {}

  public static Connection getConnection() throws SQLException {
    return ds.getConnection();
  }

  public static void evictConnection(Connection connection) {
    ds.evictConnection(connection);
  }
}
class TestClass extends DatabaseTestCase {
 @Autowired
  private HikariDataSource dataSource;

@BeforeEach
  void initData() throws SQLException {
    DataSource.ds = dataSource;
    dataSource.getHikariPoolMXBean().softEvictConnections();
    dataSource.setConnectionInitSql("set search_path to " + getTestVitmSchema() + ", public");
  }

This is how I setSchema for the Test Cases

public abstract class DatabaseTestCase {

  private static final Logger log = Logger.getLogger(DatabaseTestCase.class.getName());

  private String testSchema;

  @BeforeEach
  final void setupSchema() {
    int classHash = Math.abs(getClass().getSimpleName().hashCode());
    testSchema = String.format("test_%s", classHash);
    Map<String, String> placeholders = new HashMap<>();
    placeholders.put("schema", testSchema);
    placeholders.put("name", "xyz");
    placeholders.put("password", "123");
    placeholders.putAll(getPlaceholderReplacement());
    Flyway flyway =
        Flyway.configure()
            .dataSource(DataSource.ds)
            .schemas(testSchema)
            .placeholders(placeholders)
            .load();
    flyway.migrate();
  }

How can I set Connection Init Sql without getting the error. Thank you.



Read more here: https://stackoverflow.com/questions/64882558/error-on-setting-connectioninitsql-with-hikari-version-3-4-5

Content Attribution

This content was originally published by Tanu at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: