Skip to content

Commit 4158c7a

Browse files
committed
Remove some 6.3 references from documentation
1 parent 0d8541a commit 4158c7a

File tree

4 files changed

+20
-71
lines changed

4 files changed

+20
-71
lines changed

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

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,13 @@ class User {
6464
}
6565
----
6666

67-
Here, as usual, `example_.BY_REGION` is generated by the Metamodel Generator, and is just a constant with the value `"ByRegion"`.
68-
6967
If the `@Filter` annotation does not explicitly specify a restriction, the default restriction given by the `@FilterDef` will be applied to the entity.
7068
But an entity is free to override the default condition.
7169

7270
[source,java]
7371
----
7472
@Entity
75-
@Filter(name = example_.FILTER_BY_REGION, condition = "name = :region")
73+
@Filter(name = "ByRegion", condition = "name = :region")
7674
class Region {
7775
7876
@Id String name;
@@ -99,7 +97,7 @@ You should do this right at the _start_ of the session.
9997
[source,java]
10098
----
10199
sessionFactory.inTransaction(session -> {
102-
session.enableFilter(example_.FILTER_BY_REGION)
100+
session.enableFilter("ByRegion")
103101
.setParameter("region", "es")
104102
.validate();
105103
@@ -257,7 +255,7 @@ Native SQL queries are _not_ automatically filtered by tenant id; you'll have to
257255

258256
[TIP]
259257
====
260-
If you only need to filter rows by a static condition with no parameters, `@SQLRestriction` is a much simpler way to do that.
258+
If you only need to filter rows by a static condition with no parameters, `@Where` is a much simpler way to do that.
261259
====
262260

263261
[[custom-sql]]
@@ -648,7 +646,6 @@ These annotations allow us to specify how the elements of a collection should be
648646
| Annotation | Purpose | JPA-standard
649647

650648
| `@OrderBy` | Specifies a fragment of JPQL used to order the collection | ✔
651-
| `@SQLOrder` | Specifies a fragment of SQL used to order the collection | ✖
652649
|===
653650

654651
On the other hand, the following annotation specify how a collection should be sorted in memory, and are used for collections of type `SortedSet` or `SortedMap`:
@@ -902,7 +899,7 @@ class Book { ... }
902899

903900
Note that even though we've placed this annotation on the `Book` entity, a fetch profile—unlike an entity graph—isn't "rooted" at any particular entity.
904901

905-
We may specify association fetching strategies using the `fetchOverrides` member of the `@FetchProfile` annotation, but frankly it looks so messy that we're embarrassed to show it to you here.
902+
We may specify association fetching strategies using the `fetchOverrides` member of the `@FetchProfile` annotation.
906903

907904
[NOTE]
908905
====
@@ -914,17 +911,19 @@ A better way is to annotate an association with the fetch profiles it should be
914911

915912
[source,java]
916913
----
917-
@FetchProfile(name = "EagerBook")
914+
@FetchProfile(name = "EagerBook", fetchOverrides = {
915+
@FetchProfile.FetchOverride(entity = Book.class, association = "publisher", mode = JOIN),
916+
@FetchProfile.FetchOverride(entity = Book.class, association = "authors", mode = JOIN),
917+
@FetchProfile.FetchOverride(entity = Author.class, association = "person", mode = JOIN)
918+
})
918919
@Entity
919920
class Book {
920921
...
921922
922923
@ManyToOne(fetch = LAZY)
923-
@FetchProfileOverride(profile = Book_.PROFILE_EAGER_BOOK, mode = JOIN)
924924
Publisher publisher;
925925
926926
@ManyToMany
927-
@FetchProfileOverride(profile = Book_.PROFILE_EAGER_BOOK, mode = JOIN)
928927
Set<Author> authors;
929928
930929
...
@@ -937,33 +936,31 @@ class Author {
937936
...
938937
939938
@OneToOne
940-
@FetchProfileOverride(profile = Book_.PROFILE_EAGER_BOOK, mode = JOIN)
941939
Person person;
942940
943941
...
944942
}
945943
----
946944

947-
Here, once again, `Book_.PROFILE_EAGER_BOOK` is generated by the Metamodel Generator, and is just a constant with the value `"EagerBook"`.
948-
949945
For collections, we may even request subselect fetching:
950946

951947
[source,java]
952948
----
953-
@FetchProfile(name = "EagerBook")
954-
@FetchProfile(name = "BookWithAuthorsBySubselect")
949+
@FetchProfile(name = "EagerBook", fetchOverrides = {
950+
@FetchProfile.FetchOverride(entity = Book.class, association = "person", mode = JOIN),
951+
@FetchProfile.FetchOverride(entity = Book.class, association = "authors", mode = JOIN)
952+
})
953+
@FetchProfile(name = "BookWithAuthorsBySubselect", fetchOverrides = {
954+
@FetchProfile.FetchOverride(entity = Book.class, association = "authors", mode = SUBSELECT)
955+
})
955956
@Entity
956957
class Book {
957958
...
958959
959960
@OneToOne
960-
@FetchProfileOverride(profile = Book_.PROFILE_EAGER_BOOK, mode = JOIN)
961961
Person person;
962962
963963
@ManyToMany
964-
@FetchProfileOverride(profile = Book_.PROFILE_EAGER_BOOK, mode = JOIN)
965-
@FetchProfileOverride(profile = Book_.BOOK_WITH_AUTHORS_BY_SUBSELECT,
966-
mode = SUBSELECT)
967964
Set<Author> authors;
968965
969966
...
@@ -979,14 +976,13 @@ We may define as many different fetch profiles as we like.
979976

980977
| `@FetchProfile` | Declares a named fetch profile, optionally including a list of ``@FetchOverride``s
981978
| `@FetchProfile.FetchOverride` | Declares a fetch strategy override as part of the `@FetchProfile` declaration
982-
| `@FetchProfileOverride` | Specifies the fetch strategy for the annotated association, in a given fetch profile
983979
|===
984980

985981
A fetch profile must be explicitly enabled for a given session:
986982

987983
[source,java]
988984
----
989-
session.enableFetchProfile(Book_.PROFILE_EAGER_BOOK);
985+
session.enableFetchProfile("EagerBook");
990986
Book eagerBook = session.find(Book.class, bookId);
991987
----
992988

@@ -997,18 +993,3 @@ But Hibernate offers alternatives that we think are more compelling most of the
997993

998994
The one and only advantage unique to fetch profiles is that they let us very selectively request subselect fetching.
999995
We can't do that with entity graphs, and we can't do it with HQL.
1000-
1001-
[TIP]
1002-
====
1003-
There's a special built-in fetch profile named `org.hibernate.defaultProfile` which is defined as the profile with `@FetchProfileOverride(mode=JOIN)` applied to every eager `@ManyToOne` or `@OneToOne` association.
1004-
If you enable this profile:
1005-
1006-
[source,java]
1007-
----
1008-
session.enableFetchProfile("org.hibernate.defaultProfile");
1009-
----
1010-
1011-
Then ``outer join``s for such associations will _automatically_ be added to every HQL or criteria query.
1012-
This is nice if you can't be bothered typing out those ``join fetch``es explicitly.
1013-
And in principle it even helps partially mitigate the <<lazy-problem,problem>> of JPA having specified the wrong default for the `fetch` member of `@ManyToOne`.
1014-
====

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

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -742,20 +742,6 @@ delete.where(builder.lt(builder.year(book.get(Book_.publicationDate)), 2000));
742742
session.createMutationQuery(delete).executeUpdate();
743743
----
744744

745-
[TIP]
746-
====
747-
It's even possible to transform a HQL query string to a criteria query, and modify the query programmatically before execution:
748-
[source,java]
749-
----
750-
HibernateCriteriaBuilder builder = sessionFactory.getCriteriaBuilder();
751-
var query = builder.createQuery("from Book where year(publicationDate) > 2000", Book.class);
752-
var root = (Root<Book>) query.getRootList().get(0);
753-
query.where(builder.like(root.get(Book_.title), builder.literal("Hibernate%")));
754-
query.orderBy(builder.asc(root.get(Book_.title)), builder.desc(root.get(Book_.isbn)));
755-
List<Book> matchingBooks = session.createSelectionQuery(query).getResultList();
756-
----
757-
====
758-
759745
When all else fails, and sometimes even before that, we're left with the option of writing a query in SQL.
760746

761747
[[native-queries]]
@@ -878,24 +864,12 @@ Hibernate's `SelectionQuery` has a slightly different way to paginate the query
878864
List<Book> books =
879865
session.createSelectionQuery("from Book where title like ?1 order by title")
880866
.setParameter(1, titlePattern)
881-
.setPage(Page.first(MAX_RESULTS))
882-
.getResultList();
883-
----
884-
885-
A closely-related issue is ordering.
886-
It's quite common for pagination to be combined with the need to order query results by a field that's determined at runtime.
887-
So, as an alternative to the HQL `order by` clause, `SelectionQuery` offers the ability to specify that the query results should be ordered by one or more fields of the entity type returned by the query:
888-
889-
[source,java]
890-
----
891-
List<Book> books =
892-
session.createSelectionQuery("from Book where title like ?1")
893-
.setParameter(1, titlePattern)
894-
.setOrder(List.of(Order.asc(Book._title), Order.asc(Book._isbn)))
895867
.setMaxResults(MAX_RESULTS)
896868
.getResultList();
897869
----
898870

871+
A closely-related issue is ordering, for which Hibernate ORM 6.3 offers an incubating API.
872+
899873
Unfortunately, there's no way to do this using JPA's `TypedQuery` interface.
900874

901875
.Methods for query limits, pagination, and ordering
@@ -1021,13 +995,11 @@ We execute our named query like this:
1021995
[source,java]
1022996
----
1023997
List<Book> books =
1024-
entityManager.createNamedQuery(BookQueries_.QUERY_10_BOOKS_BY_TITLE)
998+
entityManager.createNamedQuery("10BooksByTitle")
1025999
.setParameter("titlePattern", titlePattern)
10261000
.getResultList()
10271001
----
10281002

1029-
Here, `BookQueries_.QUERY_10_BOOKS_BY_TITLE` is a constant with value `"10BooksByTitle"`, generated by the Metamodel Generator.
1030-
10311003
Note that the code which executes the named query is not aware of whether the query was written in HQL or in native SQL, making it slightly easier to change and optimize the query later.
10321004

10331005
[TIP]

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,11 @@ This is an example of a _query method_, a function which accepts arguments to th
500500
And that's all it does; it doesn't orchestrate additional program logic, and it doesn't perform transaction or session management.
501501

502502
It's even better to specify the query string using the `@NamedQuery` annotation, so that Hibernate can validate the query it at startup time, that is, when the `SessionFactory` is created, instead of when the query is first executed.
503-
Indeed, since we included the <<metamodel-generator,Metamodel Generator>> in our <<build-gradle,Gradle build>>, the query can even be validated at _compile time_.
504503

505504
We need a place to put the annotation, so lets move our query method to a new class:
506505

507506
[source,java]
508507
----
509-
@CheckHQL // validate named queries at compile time
510508
@NamedQuery(name="findBooksByTitle",
511509
query="from Book where title like :title order by title")
512510
class Queries {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,13 @@ Both batch fetching and subselect fetching are disabled by default, but we may e
225225
| Configuration property name | Property value | Alternatives
226226

227227
| `hibernate.default_batch_fetch_size` | A sensible batch size `>1` to enable batch fetching | `@BatchSize()`, `setFetchBatchSize()`
228-
| `hibernate.use_subselect_fetch` | `true` to enable subselect fetching | `@Fetch(SUBSELECT)`, `setSubselectFetchingEnabled()`
229228
|===
230229

231230
Alternatively, we can enable one or the other in a given session:
232231

233232
[source,java]
234233
----
235234
session.setFetchBatchSize(5);
236-
session.setSubselectFetchingEnabled(true);
237235
----
238236

239237
[%unbreakable]

0 commit comments

Comments
 (0)