Skip to content

Commit adea0df

Browse files
committed
expand a doc section about SS
1 parent 3205248 commit adea0df

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ List<Book> matchingBooks = selection.createQuery(session).getResultList();
400400
Notice that:
401401

402402
- The link:{doc-javadoc-url}org/hibernate/query/restriction/Restriction.html[`Restriction`] interface has static methods for constructing a variety of different kinds of restriction in a completely typesafe way.
403-
- Similarly, the link:{doc-javadoc-url}org/hibernate/query/Order.html[`Order`] class has a variety of static methods for constructing different kinds of ordering criteria.
403+
- Similarly, the link:{doc-javadoc-url}org/hibernate/query/Order.html[`Order`] interface has a variety of static methods for constructing different kinds of sorting criteria.
404404

405405
We need the following methods of link:{doc-javadoc-url}org/hibernate/query/programmatic/SelectionSpecification.html[`SelectionSpecification`]:
406406

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

+22
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,34 @@ NOTE: There's no `flush()` operation, and so `update()` is always explicit.
934934

935935
In certain circumstances, this makes stateless sessions easier to work with and simpler to reason about, but with the caveat that a stateless session is much more vulnerable to data aliasing effects, since it's easy to get two non-identical Java objects which both represent the same row of a database table.
936936

937+
Consider the following fragments:
938+
939+
[source,java]
940+
----
941+
var b1 = statelessSession.get(Book.class, isbn);
942+
var b2 = statelessSession.get(Book.class, isbn);
943+
assert b1 == b2; // fails
944+
----
945+
[source,java]
946+
----
947+
var b1 = statelessSession.get(Book.class, isbn);
948+
var b2 = statelessSession.get(Book.class, isbn);
949+
statelessSession.fetch(b1.publisher);
950+
statelessSession.fetch(b2.publisher);
951+
assert b1.publisher == b2.publisher; // fails
952+
----
953+
954+
In a stateful session, entity instances are canonicalized by primary key, and so we don't usually have two different objects representing a single row.
955+
No such canonicalization exists across invocations of a stateless session.
956+
In a stateless session, both the assertions fail.
957+
937958
[%unbreakable]
938959
[CAUTION]
939960
====
940961
If we use `fetch()` in a stateless session, we can very easily obtain two objects representing the same database row!
941962
====
942963

964+
But there are also some advantages to this model.
943965
In particular, the absence of a persistence context means that we can safely perform bulk-processing tasks without allocating huge quantities of memory.
944966
Use of a `StatelessSession` alleviates the need to call:
945967

0 commit comments

Comments
 (0)