MultiTenantConnectionProvider is required for MultiTenancyStrategy.DISCRIMINATOR

Description

Even though the method requiresMultiTenantConnectionProvider exists in MultiTenancyStrategy and as far as I can see is correct instead expressions like MultiTenancyStrategy.NONE == multiTenancyStrategy is used to determine whether ConnectionProvider or MultiTenantConnectionProvider is needed.

So with a hibernate.tenant_identifier_resolver supplied and hibernate.multiTenancy=DISCRIMINATOR I get the following error:

Caused by: java.lang.NullPointerException
at org.hibernate.internal.ContextualJdbcConnectionAccess.obtainConnection(ContextualJdbcConnectionAccess.java:43) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:115) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:145) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]

The problem as far as I can see is the if statement in the method org.hibernate.internal.AbstractSharedSessionContract#getJdbcConnectionAccess.

Environment

None

Activity

Show:
Mårten Svantesson
September 10, 2017, 6:11 PM

And if I try to work around this by supplying a MultiTenantConnectionProvider it will be ignored in org.hibernate.engine.jdbc.connections.internal.MultiTenantConnectionProviderInitiator#initiateService.

Gail Badner
September 19, 2017, 3:49 AM

Please create a pull request with a test case that reproduces your issue and your proposed fix.

Please see the org.hibernate.test.multitenancy tests for examples.

Vlad Mihalcea
September 26, 2017, 3:07 PM

Applied PR upstream.

XunBo Guo
December 10, 2019, 11:30 AM

Hi. I Want to konw the org.hibernate.MultiTenancyStrategy#DISCRIMINATORhas already imporved? and is there has some demo?

Assignee

Unassigned

Reporter

Mårten Svantesson

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure