Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some defects in repositories doc #9319

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ annotationProcessor 'org.hibernate.orm:hibernate-processor:7.0.0'

=== Excluding classes from processing

There's three ways to limit the annotation processor to certain classes:
There are three ways to limit the annotation processor to certain classes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I'm letting you change these because in principle (to a linguistic prescriptivist) "there's three ways" is grammatically "incorrect" in written English. But note that "there's many things" is something that's incredibly common in informal English and this phrase sounds completely correct to a native speaker. I would never ever notice this "mistake" in either written or spoken English.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted back

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't have to revert, it was just an observation. I agree it's strictly-speaking incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe, then I reverted back the usage of there are .... Also, the changes align with the other two docs (Hiberbate 6 introduction and Hibernate Query Language) I'd made similar changes.


1. A given repository may be excluded from processing simply by specifying `@Repository(provider="acme")` where `"acme"` is any string other than the empty string or a string equal, ignoring case, to `"Hibernate"`. This is the preferred solution when there are multiple Jakarta Data Providers available.
2. A package or type may be excluded by annotating it with the link:{doc-javadoc-url}org/hibernate/annotations/processing/Exclude.html[`@Exclude`] annotation from `org.hibernate.annotations.processing`.
Expand Down Expand Up @@ -126,7 +126,7 @@ It's always possible to instantiate a repository implementation directly.

[source,java]
----
Library library = new Library_(statelessSession);
Library library = new Library(statelessSession);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this one, please.

----

This is useful for testing, or for executing in an environment with no support for `jakarta.inject`.
Expand Down
17 changes: 9 additions & 8 deletions documentation/src/main/asciidoc/repositories/Repositories.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Book {
@Basic(optional = false)
String title;

@Basic(optional = false)
gavinking marked this conversation as resolved.
Show resolved Hide resolved
LocalDate publicationDate;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Basic(optional = false)
Expand Down Expand Up @@ -113,7 +114,7 @@ This really isn't as bad as it sounds; overuse of lazy fetching is associated wi
A future release of Jakarta Data will feature repositories backed by Jakarta Persistence stateful persistence contexts, but this functionality did not make the cut for Jakarta Data 1.0.
====

The second big difference is that instead of providing a generic interface like `EntityManager` that's capable of performing persistence operations for any entity class, Jakarta Data requires that each interaction with the database go via a user-written method specific to just one entity type. The method is marked with annotations allowing Hibernate to fill in the method implementation.
The second big difference is that instead of providing a generic interface like `EntityManager` that's capable of performing persistence operations for any entity class, Jakarta Data requires that each interaction with the database goes via a user-written method specific to just one entity type. The method is marked with annotations allowing Hibernate to fill in the method implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NathanQingyangXu this sentence is correct! English has a subjunctive mood just like Spanish does. Sure, plenty of English speakers don't use it in spoken English, but it's more correct in written English, and I do use it because I guess I read too much.

Here's what ChatGPT says about that sentence:

Yes, the sentence is grammatically correct. It conveys its meaning clearly and follows standard grammar rules. Here's a breakdown:

Subject-Verb Agreement:

The subject "Jakarta Data" correctly agrees with the verb "requires."

Subjunctive Mood:

The clause "that each interaction with the database go via a user-written method" uses the subjunctive mood correctly. The verb "go" (not "goes") is appropriate here because it's expressing a requirement or necessity.

Modifiers:

"Specific to just one entity type" modifies "method" appropriately, and the meaning is clear.
The sentence is well-constructed for a technical or formal context.

If you ask ChatGPT more about the subjunctive mood in English, I'm sure it will explain it to you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR this comes from the same reason you say "if I were ten feet tall" instead of "if I was ten feet tall". Many English speakers will use "was" here, which isn't incorrect, but "were" is more elegant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the detailed explanation. Reverted back.


For example, whereas Jakarta Persistence defines the methods `find()` and `persist()` of `EntityManager`, in Jakarta Data the application programmer is required to write an interface like the following:

Expand Down Expand Up @@ -168,7 +169,7 @@ The--perhaps surprising--answer is: it's completely up to you.
=== Organizing persistence operations

Jakarta Data lets you freely assign persistence operations to repositories according to your own preference.
In particular, Jakarta Data does not require that a repository interface inherit a built-in supertype declaring the basic "CRUD" operations, and so it's not necessary to have a separate repository interface for each entity.
In particular, Jakarta Data does not require that a repository interface inherits a built-in supertype declaring the basic "CRUD" operations, and so it's not necessary to have a separate repository interface for each entity.
gavinking marked this conversation as resolved.
Show resolved Hide resolved
You're permitted, for example, to have a single `Library` interface instead of `BookRepository`, `AuthorRepository`, and `PublisherRepository`.

Thus, the whole programming model is much more flexible than older approaches such as Spring Data, which require a repository interface per entity class, or, at least, per so-called "aggregate".
Expand Down Expand Up @@ -325,7 +326,7 @@ void add(Book... books);
[NOTE]
====
A future release of Jakarta Data might expand the list of built-in lifecycle annotations.
In particular, we're hoping to add `@Persist`, `@Merge`, `@Refresh`, `@Lock`, and `@Remove`, mapping to the fundamental operations of `EntityManager`.
In particular, we're hoping to add `@Persist`, `@Merge`, `@Refresh`, `@Lock`, and `@Remove` mapping to the fundamental operations of `EntityManager`.
gavinking marked this conversation as resolved.
Show resolved Hide resolved
====

Repositories wouldn't be useful at all if this was all they could do.
Expand All @@ -352,7 +353,7 @@ This is our first glimpse of the advantages of using Jakarta Data repositories w
====

If there is no `Book` with the given `isbn` in the database, the method throws `EmptyResultException`.
There's two ways around this if that's not what we want:
There are two ways around this if that's not what we want:

- declare the method to return `Optional`, or
- annotate the method `@jakarta.annotation.Nullable`.
Expand Down Expand Up @@ -399,7 +400,7 @@ Furthermore, if the parameter type is a list or array of the entity field type,
List<Book> books(String[] ibsn);
----

Or course, an automatic query method might have multiple parameters.
Of course, an automatic query method might have multiple parameters.

[source,java]
----
Expand Down Expand Up @@ -462,7 +463,7 @@ List<Book> booksByTitle(String pattern);
You might notice that:

- The `from` clause is not required in JDQL, and is inferred from the return type of the repository method.
- Since Jakarta Persistence 3.2, neither the `select` cause nor entity aliases (identification variables) are required in JPQL, finally standardizing a very old feature of HQL.
- Since Jakarta Persistence 3.2, neither the `select` clause nor entity aliases (identification variables) are required in JPQL, finally standardizing a very old feature of HQL.

This allows simple queries to be written in a very compact form.

Expand Down Expand Up @@ -493,7 +494,7 @@ The JPQL specification provides the `select new` construct for this.

[source,java]
----
@Query("select new AuthorBookRecord(b.isbn, a.ssn, a.name, b.title " +
@Query("select new AuthorBookRecord(b.isbn, a.ssn, a.name, b.title) " +
"from Author a join books b " +
"where title like :pattern")
List<AuthorBookSummary> summariesForTitle(@Pattern String pattern);
Expand All @@ -509,7 +510,7 @@ Since this is quite verbose, Hibernate doesn't require the use of `select new`,
@Query("select isbn, ssn, name, title " +
"from Author join books " +
"where title like :pattern")
List<AuthorBookSummary> summariesForTitle(@Pattern String pattern);
List<AuthorBookSummary> summariesForTitle(String pattern);
gavinking marked this conversation as resolved.
Show resolved Hide resolved
----
====

Expand Down