hibernate-orm icon indicating copy to clipboard operation
hibernate-orm copied to clipboard

HHH-18685 proposed basic enhancement to allow subclasses to have already initialized the HikariDataSource

Open bodhi-one opened this issue 1 year ago • 4 comments

…ady initialized the HikariDataSource

Provide HikariCPConnectionProvider ability to use a pre-configured HikariDataSource already initialized by subclasses. Many more details in the Jira.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion. For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-18685

bodhi-one avatar Oct 03 '24 20:10 bodhi-one

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+     ↳ Offending commits: [6da8f7427de3ff4a3c5f47c5c2191e6f0a5d2dea]

› This message was automatically generated.

Changes made as requested.

bodhi-one avatar Oct 08 '24 14:10 bodhi-one

Please also squash and rebase the commits.

beikov avatar Oct 09 '24 07:10 beikov

Hi @beikov , sorry, myself and another very smart guy tried to do this, but we are having issues, can you please give us exact steps.

git rebase -i HEAD~2 error: cannot 'squash' without a previous commit You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'. Or you can abort the rebase with 'git rebase --abort'.

bodhi-one avatar Oct 09 '24 15:10 bodhi-one

Since HikariDataSource is a DataSource why not just use DatasourceConnectionProviderImpl?

sebersole avatar Oct 16 '24 14:10 sebersole

Since HikariDataSource is a DataSource why not just use DatasourceConnectionProviderImpl?

Hi @sebersole - we have already bootstrapped HikariCP, Hibernate will next call looking for the ConnectionProvider, and it will bypass our HikariDataSource, already created by us because of our unique configuration, we just need HikariCPConnectionProvider to allow us to provide our HikariDataSource in place of creating another one. If we extended a non-Hikari Hibernate class, wouldn't that prevent us from being wired up into the existing HikariCP pools (that we just created) ?

bodhi-one avatar Oct 16 '24 15:10 bodhi-one

You are clearly configuring Hibernate ORM in a programmatic fashion since you pass an object HikariDataSource as value somehow. Instead of changing the HikariCPConnectionProvider implementation, you could rather use DatasourceConnectionProviderImpl directly i.e. replace

  .setProperty("hibernate.hikari.HikariDataSource", hikariDataSource)

with

  DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl();
  connectionProvider.setDataSource( hikariDataSource );
  .setProperty("hibernate.connection.provider_class", connectionProvider)

beikov avatar Oct 16 '24 17:10 beikov

You are clearly configuring Hibernate ORM in a programmatic fashion since you pass an object HikariDataSource as value somehow. Instead of changing the HikariCPConnectionProvider implementation, you could rather use DatasourceConnectionProviderImpl directly i.e. replace

  .setProperty("hibernate.hikari.HikariDataSource", hikariDataSource)

with

  DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl();
  connectionProvider.setDataSource( hikariDataSource );
  .setProperty("hibernate.connection.provider_class", connectionProvider)

Hi, I'm not following. Do you mean for us to extend DatasourceConnectionProviderImpl or to submit a PR for these changes you outlined above directly into DatasourceConnectionProviderImpl.

If you meant for us to extend DatasourceConnectionProviderImpl, then at what interaction would we override the base code with what you have suggested?

bodhi-one avatar Oct 17 '24 14:10 bodhi-one

Have you looked at DatasourceConnectionProviderImpl?

Its hard to answer these usage questions without seeing your actual code. The important bit here is when/how you create the HikariDataSource relative to when/how you bootstrap Hibernate. But assuming "normal" start up, something like:

HikariDataSource hikariDatasource = ...;
SessionFactory = new Configuration()
        .setProperty( "hibernate.connection.datasource", hikariDatasource )
        ...
        .buildSessionFactory();

sebersole avatar Oct 17 '24 15:10 sebersole