Skip to content

Commit 0b62ea3

Browse files
committed
[#764] Fix multitenancy without a CurrentTenantIdentifierResolver
1 parent 44ae3d0 commit 0b62ea3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinySessionFactoryImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Mutiny.Session openSession() {
7474
@Override
7575
public Mutiny.Session openSession(String tenantId) {
7676
return new MutinySessionImpl(
77-
new ReactiveSessionImpl( delegate, options(), proxyConnection( tenantId ) ),
77+
new ReactiveSessionImpl( delegate, options( tenantId ), proxyConnection( tenantId ) ),
7878
this
7979
);
8080
}
@@ -88,7 +88,7 @@ Uni<Mutiny.Session> newSession() throws HibernateException {
8888

8989
Uni<Mutiny.Session> newSession(String tenantId) throws HibernateException {
9090
return uni( () -> connection( tenantId ) )
91-
.map( reactiveConnection -> new ReactiveSessionImpl( delegate, options(), reactiveConnection ) )
91+
.map( reactiveConnection -> new ReactiveSessionImpl( delegate, options( tenantId ), reactiveConnection ) )
9292
.map( s -> new MutinySessionImpl(s, this) );
9393
}
9494

@@ -112,6 +112,11 @@ private SessionCreationOptions options() {
112112
return new SessionFactoryImpl.SessionBuilderImpl<>( delegate );
113113
}
114114

115+
private SessionCreationOptions options(String tenantIdentifier) {
116+
return (SessionCreationOptions) new SessionFactoryImpl.SessionBuilderImpl<>( delegate )
117+
.tenantIdentifier( tenantIdentifier );
118+
}
119+
115120
private CompletionStage<ReactiveConnection> connection(String tenantId) {
116121
assertUseOnEventLoop();
117122
return tenantId == null

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageSessionFactoryImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Stage.Session openSession() {
7070
@Override
7171
public Stage.Session openSession(String tenantId) {
7272
return new StageSessionImpl(
73-
new ReactiveSessionImpl( delegate, options(), proxyConnection( tenantId ) ),
73+
new ReactiveSessionImpl( delegate, options( tenantId ), proxyConnection( tenantId ) ),
7474
this
7575
);
7676
}
@@ -92,7 +92,7 @@ CompletionStage<Stage.Session> newSession() {
9292

9393
CompletionStage<Stage.Session> newSession(String tenantId) {
9494
return stage( v -> connection( tenantId )
95-
.thenApply( connection -> new ReactiveSessionImpl( delegate, options(), connection ) )
95+
.thenApply( connection -> new ReactiveSessionImpl( delegate, options( tenantId ), connection ) )
9696
.thenApply( s -> new StageSessionImpl(s, this) ) );
9797
}
9898

@@ -107,6 +107,11 @@ private SessionCreationOptions options() {
107107
return new SessionFactoryImpl.SessionBuilderImpl<>( delegate );
108108
}
109109

110+
private SessionCreationOptions options(String tenantIdentifier) {
111+
return (SessionCreationOptions) new SessionFactoryImpl.SessionBuilderImpl<>( delegate )
112+
.tenantIdentifier( tenantIdentifier );
113+
}
114+
110115
private CompletionStage<ReactiveConnection> connection(String tenantId) {
111116
return tenantId == null
112117
? connectionPool.getConnection()

0 commit comments

Comments
 (0)