Skip to content

Commit 8b00b94

Browse files
committed
doc: documente hibernate stateless session
1 parent 2ba0124 commit 8b00b94

1 file changed

Lines changed: 59 additions & 7 deletions

File tree

docs/asciidoc/modules/hibernate.adoc

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
== Hibernate
22

3-
https://hibernate.org/orm/[Hibernate ORM] module.
3+
https://hibernate.org/orm/[Hibernate ORM] module.
44

55
=== Usage
66

@@ -119,8 +119,8 @@ options for more explicit control:
119119

120120
=== Transactional Request
121121

122-
The javadoc:hibernate.TransactionalRequest[] decorator takes care of a lifecycle of an `EntityManager` per HTTP request.
123-
The decorator creates, bind, begin/commit/rollback transaction and finally close it, so route handler
122+
The javadoc:hibernate.TransactionalRequest[] filter takes care of a lifecycle of an `EntityManager`/`StatelessSession` per HTTP request.
123+
The filter creates, bind, begin/commit/rollback transaction and finally close it, so route handler
124124
doesn't have to deal with that boring lines of code.
125125

126126
.TransactionalRequest
@@ -175,17 +175,69 @@ import io.jooby.hibernate.TransactionalRequest
175175
}
176176
----
177177

178-
The `EntityManager` is tied to the current HTTP request. Multiple `require`/`injection` calls produce
179-
the same `EntityManager`. It is a simple way of managed simple read/write operations.
178+
.TransactionalRequest with StatelessSession
179+
[source, java, role = "primary"]
180+
----
181+
import io.jooby.hikari.HikariModule;
182+
import io.jooby.hibernate.HibernateModule;
183+
import io.jooby.hibernate.TransactionalRequest;
184+
185+
{
186+
install(new HikariModule());
187+
188+
install(new HibernateModule());
189+
190+
use(new TransactionalRequest().useStatelessSession());
191+
192+
post("/create", ctx -> {
193+
StatelessSession session = require(StatelessSession.class);
194+
195+
MyEntity e = ...;
196+
197+
session.insert(e);
198+
199+
return e;
200+
});
201+
}
202+
----
203+
204+
.Kotlin
205+
[source, kt, role="secondary"]
206+
----
207+
import io.jooby.hikari.HikariModule
208+
import io.jooby.hibernate.HibernateModule
209+
import io.jooby.hibernate.TransactionalRequest
210+
211+
{
212+
install(HikariModule())
213+
214+
install(HibernateModule())
215+
216+
use(TransactionalRequest().useStatelessSession())
217+
218+
post("/create") { ctx ->
219+
val session = require(StatelessSession::class)
220+
221+
val e = ...
222+
223+
session.insert(e)
224+
225+
e
226+
}
227+
}
228+
----
229+
230+
The `EntityManager`/`StatelessSession` is tied to the current HTTP request. Multiple `require`/`injection` calls produce
231+
the same `EntityManager`/`StatelessSession`. It is a simple way of managed simple read/write operations.
180232

181233
[NOTE]
182234
====
183-
The javadoc:hiernate.TransactionalRequest[] doesn't extend session to the rendering phase (json, html, etc.).
235+
The javadoc:hibernate.TransactionalRequest[] doesn't extend session to the rendering phase (json, html, etc.).
184236
The route handler needs to make sure all the information required by the rendering phase is available.
185237
Otherwise, you are going to see `LazyInitializationException`.
186238
====
187239

188-
There is a javadoc:hibernate.SessionRequest[] decorator that works identically but leaves transaction
240+
There is a javadoc:hibernate.SessionRequest[] filter that works identically but leaves transaction
189241
management to you, so no transaction is started/committed or rollback during a HTTP request.
190242

191243
==== @Transactional

0 commit comments

Comments
 (0)