Skip to content

Commit f0a17e9

Browse files
committed
doc new feature Steve just added
1 parent eafe6fd commit f0a17e9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

documentation/src/main/asciidoc/introduction/Advanced.adoc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,20 @@ var session =
126126
.openSession();
127127
----
128128

129-
However, since we often don't have this level of control of creation of the session, it's more common to supply an implementation of `CurrentTenantIdentifierResolver` to Hibernate.
129+
Or, when using JPA-standard APIs:
130+
131+
[source,java]
132+
----
133+
var entityManager =
134+
entityManagerFactory.createEntityManager(Map.of(HibernateHints.HINT_TENANT_ID, tenantId));
135+
----
136+
137+
However, since we often don't have this level of control over creation of the session, it's more common to supply an implementation of `CurrentTenantIdentifierResolver` to Hibernate.
130138

131139
There are three common ways to implement multi-tenancy:
132140

133141
1. each tenant has its own database,
134-
2. each tenant has its own schema,
142+
2. each tenant has its own schema, or
135143
3. tenants share tables in a single schema, and rows are tagged with the tenant id.
136144

137145
From the point of view of Hibernate, there's little difference between the first two options.
@@ -156,6 +164,7 @@ In this case we don't need a `MultiTenantConnectionProvider`, but we will need a
156164
class Account {
157165
@Id String id;
158166
@TenantId String tenantId;
167+
159168
...
160169
}
161170
----
@@ -177,6 +186,10 @@ Native SQL queries are _not_ automatically filtered by tenant id; you'll have to
177186
| `hibernate.multi_tenant_connection_provider` | Specifies the `MultiTenantConnectionProvider`
178187
|===
179188

189+
[TIP]
190+
====
191+
If you only need to filter rows by a static condition with no parameters, `@SQLRestriction` is a much simpler way to do that.
192+
====
180193

181194
[[custom-sql]]
182195
=== Using custom-written SQL

0 commit comments

Comments
 (0)