Persistence.createEntityManagerFactory("testPU") fails, if persistence unit has config & CurrentTenantIdentifierResolver is not null.

Description

Starting from Hibernate 5.4.5

Persistence.createEntityManagerFactory("testPU") fails, if testPU configured in persistence.xml & CurrentTenantIdentifierResolver is not null.

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java#L382 → When Session factory created, this withOptions() called by default, same applies for HibernatePersistanceProvider.createEntityManagerFactory method, which also calls same constructor via SessionFactoryBuilderImpl.build & try to resolve the current tenant. Problem is, my implementation, and probably many others as well, uses some runtime created, request/thread specific objects, like current request or ThreadLocal values etc, to determine the current tenant.

I confirm that it’s working in 5.3. In fact, line 382 added in 5.4.5, which causes the issue.

Here's a MWE -> https://github.com/gokhanoner/hibernate-emf-tenant-resolver-issue

Running tests fails, since it's using Hibernate > 5.4.4 & you can see that it's calling TenantResolver. Change the Hibernate version to 5.4.4 or lower or 5.3.X, test passes.

Environment

None

Activity

Show:
Gokhan Oner
December 24, 2020, 11:08 AM

There’s another issue, opened about a year ago & closed without a proper fix →

Gokhan Oner
January 6, 2021, 11:08 PM

any update on this issue??

Gokhan Oner
2 days ago

any other way to get some interest to this ticket?

Assignee

Unassigned

Reporter

Gokhan Oner

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure