Skip to content

Commit cfae086

Browse files
nathan.xugavinking
authored andcommitted
HHH-18588 fix minor defects in Hibernate Introduction doc
1 parent 072d3e2 commit cfae086

File tree

8 files changed

+40
-38
lines changed

8 files changed

+40
-38
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public static class Person { ... }
349349
| link:{doc-javadoc-url}org/hibernate/annotations/SQLSelect.html[`@SQLSelect`] | Overrides a generated SQL `select` statement
350350
| link:{doc-javadoc-url}org/hibernate/annotations/SQLInsert.html[`@SQLInsert`] | Overrides a generated SQL `insert` statement
351351
| link:{doc-javadoc-url}org/hibernate/annotations/SQLUpdate.html[`@SQLUpdate`] | Overrides a generated SQL `update` statement
352-
| link:{doc-javadoc-url}org/hibernate/annotations/SQDelete.html[`@SQDelete`] | Overrides a generated SQL `delete` statement a single rows
352+
| link:{doc-javadoc-url}org/hibernate/annotations/SQDelete.html[`@SQDelete`] | Overrides a generated SQL `delete` statement for a single row
353353
| link:{doc-javadoc-url}org/hibernate/annotations/SQDeleteAll.html[`@SQDeleteAll`] | Overrides a generated SQL `delete` statement for multiple rows
354354
| link:{doc-javadoc-url}org/hibernate/annotations/SQLRestriction.html[`@SQLRestriction`] | Adds a restriction to generated SQL
355355
| link:{doc-javadoc-url}org/hibernate/annotations/SQLOrder.html[`@SQLOrder`] | Adds an ordering to generated SQL

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
== Configuration and bootstrap
33

44
We would love to make this section short.
5-
Unfortunately, there's several distinct ways to configure and bootstrap Hibernate, and we're going to have to describe at least two of them in detail.
5+
Unfortunately, there are several distinct ways to configure and bootstrap Hibernate, and we're going to have to describe at least two of them in detail.
66

77
The four basic ways to obtain an instance of Hibernate are shown in the following table:
88

9-
[%breakable,cols="50,50"]
9+
[%breakable,cols="50,50",number=0]
1010
|===
1111

1212
| Using the standard JPA-defined XML, and the operation `Persistence.createEntityManagerFactory()`
@@ -65,13 +65,13 @@ driver for your database.
6565
| MySQL or TiDB | `com.mysql:mysql-connector-j:{version}`
6666
| MariaDB | `org.mariadb.jdbc:mariadb-java-client:{version}`
6767
| DB2 | `com.ibm.db2:jcc:{version}`
68-
| SQL Server | `com.microsoft.sqlserver:mssql-jdbc:${version}`
69-
| Oracle | `com.oracle.database.jdbc:ojdbc11:${version}`
68+
| SQL Server | `com.microsoft.sqlserver:mssql-jdbc:{version}`
69+
| Oracle | `com.oracle.database.jdbc:ojdbc11:{version}`
7070
| H2 | `com.h2database:h2:{version}`
7171
| HSQLDB | `org.hsqldb:hsqldb:{version}`
7272
|===
7373

74-
Where `{version}` is the latest version of the JDBC driver for your databse.
74+
Where `{version}` is the latest version of the JDBC driver for your database.
7575

7676
[[optional-dependencies]]
7777
=== Optional dependencies
@@ -310,7 +310,7 @@ jakarta.persistence.database-major-version=15
310310
jakarta.persistence.database-minor-version=7
311311
----
312312

313-
The product name is the value returned by `java.sql.DatabaseMetaData.getDatabaseProductName()`, for example, `PostgreSQL`, `MySQL` `H2`, `Oracle`, `EnterpriseDB`, `MariaDB`, or `Microsoft SQL Server`.
313+
The product name is the value returned by `java.sql.DatabaseMetaData.getDatabaseProductName()`, for example, `PostgreSQL`, `MySQL`, `H2`, `Oracle`, `EnterpriseDB`, `MariaDB`, or `Microsoft SQL Server`.
314314

315315
.Settings needed when database is inaccessible at startup
316316
[%breakable,cols="50,~"]
@@ -424,7 +424,7 @@ Persistence.generateSchema("org.hibernate.example",
424424

425425
To see the generated SQL as it's sent to the database, you have two options.
426426

427-
One way is to set the property `hibernate.show_sql` to `true`, and Hibernate will log SQL direct to the console.
427+
One way is to set the property `hibernate.show_sql` to `true`, and Hibernate will log SQL directly to the console.
428428
You can make the output much more readable by enabling formatting or highlighting.
429429
These settings really help when troubleshooting the generated SQL statements.
430430

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ There are two ways to apply a converter:
649649
- the `@Convert` annotation applies an `AttributeConverter` to a particular entity attribute, or
650650
- the `@Converter` annotation (or, alternatively, the `@ConverterRegistration` annotation) registers an `AttributeConverter` for automatic application to all attributes of a given type.
651651

652-
For example, the following converter will be automatically applied to any attribute of type `BitSet`, and takes care of persisting the `BitSet` to a column of type `varbinary`:
652+
For example, the following converter will be automatically applied to any attribute of type `EnumSet<DayOfWeek>`, and takes care of persisting the `EnumSet<DayOfWeek>` to a column of type `INTEGER`:
653653

654654
[source,java]
655655
----
@@ -687,9 +687,9 @@ On the other hand, if we _don't_ set `autoapply=true`, then we must explicitly a
687687

688688
[source,java]
689689
----
690-
@Convert(converter = BitSetConverter.class)
690+
@Convert(converter = EnumSetConverter.class)
691691
@Basic(optional = false)
692-
BitSet bitset;
692+
EnumSet<DayOfWeek> daysOfWeek;
693693
----
694694

695695
All this is nice, but it probably won't surprise you that Hibernate goes beyond what is required by JPA.
@@ -738,7 +738,7 @@ Alternatively, the `@JavaTypeRegistration` annotation may be used to register `B
738738
[discrete]
739739
==== JdbcType
740740

741-
A `org.hibernate.type.descriptor.jdbc.JdbcType` is able to read and write a single Java type from and to JDBC.
741+
An `org.hibernate.type.descriptor.jdbc.JdbcType` is able to read and write a single Java type from and to JDBC.
742742

743743
For example, `VarcharJdbcType` takes care of:
744744

@@ -1233,7 +1233,7 @@ class Book {
12331233

12341234
Remember, if we wish to the modify the collection we must <<bidirectional-problem,change the owning side>>.
12351235

1236-
We've again used ``Set``s to represent the association.
1236+
We've again used `Set` to represent the association.
12371237
As before, we have the option to use `Collection` or `List`.
12381238
But in this case it _does_ make a difference to the semantics of the association.
12391239

@@ -1486,7 +1486,7 @@ Let's pause to remember the annotations we've met so far.
14861486
| Annotation | Purpose | JPA-standard
14871487

14881488
| `@GeneratedValue` | Specify that an identifier is system-generated | &#10004;
1489-
| `@SequenceGenerator` | Define an id generated backed by on a database sequence | &#10004;
1489+
| `@SequenceGenerator` | Define an id generated backed by a database sequence | &#10004;
14901490
| `@TableGenerator` | Define an id generated backed by a database table | &#10004;
14911491
| `@IdGeneratorType` | Declare an annotation that associates a custom `Generator` with each `@Id` attribute it annotates | &#10006;
14921492
| `@ValueGenerationType` | Declare an annotation that associates a custom `Generator` with each `@Basic` attribute it annotates | &#10006;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ interface Queries {
576576
}
577577
----
578578

579-
This gives some dynamic control over query execution, but what if would like direct control over the `Query` object?
579+
This gives some dynamic control over query execution, but what if we would like direct control over the `Query` object?
580580
Well, let's talk about the return type.
581581

582582
[[key-based-paging]]

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Session session = entityManager.unwrap(Session.class);
2121
====
2222

2323
An instance of `Session` (or of `EntityManager`) is a _stateful session_.
24-
It mediates the interaction between your program and the database via a operations on a _persistence context_.
24+
It mediates the interaction between your program and the database via operations on a _persistence context_.
2525

2626
In this chapter, we're not going to talk much about `StatelessSession`.
2727
We'll come back to <<stateless-sessions,this very useful API>> when we talk about performance.
@@ -576,9 +576,9 @@ session.getTransaction().commit();
576576

577577
A second way to reduce the cost of flushing is to load entities in _read-only_ mode:
578578

579-
- `Session.setDefaultReadOnly(false)` specifies that all entities loaded by a given session should be loaded in read-only mode by default,
580-
- `SelectionQuery.setReadOnly(false)` specifies that every entity returned by a given query should be loaded in read-only mode, and
581-
- `Session.setReadOnly(Object, false)` specifies that a given entity already loaded by the session should be switched to read-only mode.
579+
- `Session.setDefaultReadOnly(true)` specifies that all entities loaded by a given session should be loaded in read-only mode by default,
580+
- `SelectionQuery.setReadOnly(true)` specifies that every entity returned by a given query should be loaded in read-only mode, and
581+
- `Session.setReadOnly(Object, true)` specifies that a given entity already loaded by the session should be switched to read-only mode.
582582

583583
It's not necessary to dirty-check an entity instance in read-only mode.
584584

@@ -793,7 +793,7 @@ Execution of a criteria query works almost exactly like execution of HQL.
793793
| Kind | `Session` method | `EntityManager` method | `Query` execution method
794794

795795
| Selection | `createSelectionQuery(CriteriaQuery)` | `createQuery(CriteriaQuery)` | `getResultList()`, `getSingleResult()`, or `getSingleResultOrNull()`
796-
| Mutation | `createMutationQuery(CriteriaUpdate)` or `createQuery(CriteriaDelete)` | `createQuery(CriteriaUpdate)` or `createQuery(CriteriaDelte)` | `executeUpdate()`
796+
| Mutation | `createMutationQuery(CriteriaUpdate)` or `createMutationQuery(CriteriaDelete)` | `createQuery(CriteriaUpdate)` or `createQuery(CriteriaDelte)` | `executeUpdate()`
797797
|===
798798

799799
For example:
@@ -886,10 +886,12 @@ For the most simple cases, Hibernate can infer the shape of the result set:
886886
----
887887
Book book =
888888
session.createNativeQuery("select * from Books where isbn = ?1", Book.class)
889+
.setParameter(1, isbn)
889890
.getSingleResult();
890891
891892
String title =
892893
session.createNativeQuery("select title from Books where isbn = ?1", String.class)
894+
.setParameter(1, isbn)
893895
.getSingleResult();
894896
----
895897

@@ -905,7 +907,7 @@ So if there are any unflushed changes to ``Book``s, this query might return stal
905907
----
906908
List<Book> books =
907909
session.createNativeQuery("select * from Books", Book.class)
908-
.getResultList()
910+
.getResultList();
909911
----
910912

911913
There's two ways to ensure the persistence context is flushed before this query is executed.
@@ -917,7 +919,7 @@ Either, we could simply force a flush by calling `flush()` or by setting the flu
917919
List<Book> books =
918920
session.createNativeQuery("select * from Books", Book.class)
919921
.setHibernateFlushMode(ALWAYS)
920-
.getResultList()
922+
.getResultList();
921923
----
922924

923925
Or, alternatively, we could tell Hibernate which modified state affects the results of the query:
@@ -927,7 +929,7 @@ Or, alternatively, we could tell Hibernate which modified state affects the resu
927929
List<Book> books =
928930
session.createNativeQuery("select * from Books", Book.class)
929931
.addSynchronizedEntityClass(Book.class)
930-
.getResultList()
932+
.getResultList();
931933
----
932934

933935
[TIP]
@@ -995,7 +997,7 @@ The `getResultCount()` method is useful for displaying the number of pages of re
995997
SelectionQuery<Book> query =
996998
session.createSelectionQuery("from Book where title like ?1 order by title", Book.class)
997999
.setParameter(1, titlePattern);
998-
long pages = query.getResultCount() / MAX_RESULTS;
1000+
long pages = (long) Math.ceil(query.getResultCount() * 1.0 / MAX_RESULTS);
9991001
List<Book> books = query.setMaxResults(MAX_RESULTS).getResultList();
10001002
----
10011003

@@ -1061,7 +1063,7 @@ if (!firstPage.isLastPage()) {
10611063
----
10621064

10631065
The "key" in key-based pagination refers to a unique key of the result set which determines a total order on the query results.
1064-
In this example, `Book.isbn` is the key.
1066+
In this example, `Book_.isbn` is the key.
10651067

10661068
Since this code is a little bit fiddly, key-based pagination works best with <<key-based-paging,generated query or finder methods>>.
10671069

@@ -1121,7 +1123,7 @@ var bookIsbn = book.get(Book_.isbn);
11211123
var bookPrice = book.get(Book_.price);
11221124
query.select(builder.tuple(bookTitle, bookIsbn, bookPrice));
11231125
var resultList = session.createSelectionQuery(query).getResultList();
1124-
for (var result: resultList) {
1126+
for (var result : resultList) {
11251127
String title = result.get(bookTitle);
11261128
String isbn = result.get(bookIsbn);
11271129
BigDecimal price = result.get(bookPrice);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Hibernate makes *relational data* visible to a program written in Java, in a *na
1313
3. allowing performance optimizations to be made after the basic persistence logic has already been written.
1414
****
1515

16-
Here the relational data is the focus, along with the importance of typesafety.
16+
Here the relational data is the focus, along with the importance of type safety.
1717
The goal of _object/relational mapping_ (ORM) is to eliminate fragile and untypesafe code, and make large programs easier to maintain in the long run.
1818

1919
ORM takes the pain out of persistence by relieving the developer of the need to hand-write tedious, repetitive, and fragile code for flattening graphs of objects to database tables and rebuilding graphs of objects from flat SQL query result sets.
@@ -409,7 +409,7 @@ public class Main {
409409
In practice, we never access the database directly from a `main()` method.
410410
So now let's talk about how to organize persistence logic in a real system.
411411
The rest of this chapter is not compulsory.
412-
If you're itching for more details about Hibernate itself, you're quite welcome to skip straight to the <<entities,next chapter>>, and come back later.
412+
If you're itching for more details about Hibernate itself, you're quite welcome to skip straight to the <<configuration,next chapter>>, and come back later.
413413

414414
[[organizing-persistence]]
415415
=== Organizing persistence logic
@@ -462,7 +462,7 @@ Let's now consider a slightly more complicated case.
462462
----
463463
@Path("/") @Produces("application/json")
464464
public class BookResource {
465-
private static final RESULTS_PER_PAGE = 20;
465+
private static final int RESULTS_PER_PAGE = 20;
466466
467467
@GET @Path("books/{titlePattern}/{page:\\d+}")
468468
public List<Book> findBooks(String titlePattern, int page) {
@@ -497,10 +497,10 @@ static List<Book> findBooksByTitleWithPagination(Session session,
497497
This is an example of a _query method_, a function which accepts arguments to the parameters of a HQL or SQL query, and executes the query, returning its results to the caller.
498498
And that's all it does; it doesn't orchestrate additional program logic, and it doesn't perform transaction or session management.
499499

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

503-
We need a place to put the annotation, so lets move our query method to a new class:
503+
We need a place to put the annotation, so let's move our query method to a new class:
504504

505505
[source,java]
506506
----
@@ -614,7 +614,7 @@ We do need to be careful here if our persistence code uses native SQL, or if it
614614
====
615615

616616
Whether we're testing against our real database, or against an in-memory Java database, we'll need to export the schema at the beginning of a test suite.
617-
We _usually_ do this when we create the Hibernate `SessionFactory` or JPA `EntityManager`, and so traditionally we've used a <<automatic-schema-export,configuration property>> for this.
617+
We _usually_ do this when we create the Hibernate `SessionFactory` or JPA `EntityManagerFactory`, and so traditionally we've used a <<automatic-schema-export,configuration property>> for this.
618618

619619
The JPA-standard property is `jakarta.persistence.schema-generation.database.action`.
620620
For example, if we're using `Configuration` to configure Hibernate, we could write:
@@ -686,7 +686,7 @@ Then testing persistence logic is now straightforward!
686686

687687
You'll need to:
688688

689-
- bootstrap Hibernate and create a `SessionFactory` or `EntityManagerFactory` and the beginning of your test suite (we've already seen how to do that), and
689+
- bootstrap Hibernate and create a `SessionFactory` or `EntityManagerFactory` at the beginning of your test suite (we've already seen how to do that), and
690690
- create a new `Session` or `EntityManager` inside each `@Test` method, using `inTransaction()`, for example.
691691

692692
Actually, some tests might require multiple sessions.
@@ -718,7 +718,7 @@ Let's now consider a different approach to code organization, one we treat with
718718
[WARNING]
719719
====
720720
In this section, we're going to give you our _opinion_.
721-
If you're only interested in facts, or if you prefer not to read things that might undermine the opinion you currently hold, please feel free to skip straight to the <<entities,next chapter>>.
721+
If you're only interested in facts, or if you prefer not to read things that might undermine the opinion you currently hold, please feel free to skip straight to the <<configuration,next chapter>>.
722722
====
723723

724724
Hibernate is an architecture-agnostic library, not a framework, and therefore integrates comfortably with a wide range of Java frameworks and containers.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ In principle, the `Blob` and `Clob` objects provide efficient ways to read or st
711711
----
712712
Book book = session.find(Book.class, bookId);
713713
String text = book.text.getSubString(1, textLength);
714-
InputStream bytes = book.images.getBinaryStream();
714+
InputStream bytes = book.coverArt.getBinaryStream();
715715
----
716716

717717
Of course, the behavior here depends very much on the JDBC driver, and so we really can't promise that this is a sensible thing to do on your database.
@@ -1035,7 +1035,7 @@ But it's common to need to:
10351035

10361036
We've <<join-column-mappings,already seen>> how to use `@ForeignKey` to specify the name of a foreign key constraint.
10371037

1038-
There's two ways to add a unique constraint to a table:
1038+
There are two ways to add a unique constraint to a table:
10391039

10401040
- using `@Column(unique=true)` to indicate a single-column unique key, or
10411041
- using the `@UniqueConstraint` annotation to define a uniqueness constraint on a combination of columns.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ hibernate.agroal.reapTimeout PT10s
4848
----
4949

5050
As long as you set at least one property with the prefix `hibernate.agroal`, the `AgroalConnectionProvider` will be selected automatically.
51-
There's many to choose from:
51+
There are many to choose from:
5252

5353
.Settings for configuring Agroal
5454
[%breakable,cols="37,~"]
@@ -583,7 +583,7 @@ If there are multiple implementations on the classpath, we must disambiguate usi
583583
|===
584584
| Configuration property name | Property value
585585

586-
| `hibernate.javax.cache.provider` a| The implementation of `javax.cache.spiCachingProvider`, for example:
586+
| `hibernate.javax.cache.provider` a| The implementation of `javax.cache.spi.CachingProvider`, for example:
587587
[%breakable,cols="~,20"]
588588
!===
589589
! `org.ehcache.jsr107.EhcacheCachingProvider` ! for EHCache

0 commit comments

Comments
 (0)