3

I am running a java app (java 1.7) with hibernate 4.2.0 and I need to implement a schema based multi tenancy setup. I used this exampleto do that. my problem is that I was unable to figure out how to create the connection providers. the example uses:

    acmeProvider = ConnectionProviderBuilder.buildConnectionProvider( "acme" );
    jbossProvider = ConnectionProviderBuilder.buildConnectionProvider( "jboss" );

but ConnectionProviderBuilder is for testing use.

I tried to use the following:

    C3P0ConnectionProvider connectionProvider = new C3P0ConnectionProvider()
    {
        public boolean supportsAggressiveRelease()
        {
            return allowAggressiveRelease;
        }
    };

    connectionProvider.configure(props);

the problem here was that the C3P0ConnectionProvider has a null serviceRegistry which crush the with NPE.

does anyone have an idea on how to create ConnectionProvider for each tenant?

Thanks,

Ronen

rperez
  • 8,430
  • 11
  • 36
  • 44
  • https://stackoverflow.com/questions/26968721/manage-connection-pooling-in-multi-tenant-app-using-hibernate ? – Optional Jul 31 '21 at 14:40

1 Answers1

0

Try suggestion using Properties to add data source properties:

DatasourceConnectionProviderImpl cp = new DatasourceConnectionProviderImpl();
cp.setDataSource(ds);
Properties p = new Properties();
// ...
cp.configure(p);

Or with DriverManagerConnectionProviderImpl:

DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl() {
   public boolean supportsAggressiveRelease() {
     return allowAggressiveRelease;
   }
 };
 connectionProvider.configure( props );
Ori Marko
  • 56,308
  • 23
  • 131
  • 233