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

Add a note about HR not being a replacement for ORM #35777

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 17 additions & 7 deletions docs/src/main/asciidoc/hibernate-reactive-panache.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
It makes complex mappings possible, but it does not make simple and common mappings trivial.
Hibernate Reactive with Panache focuses on making your entities trivial and fun to write in Quarkus.

[NOTE]
====
Hibernate Reactive is not a replacement for xref:hibernate-orm-panache.adoc[Hibernate ORM] or the future of Hibernate ORM.
It is a different stack tailored for reactive use cases where you need high-concurrency.

Furthermore, using RESTEasy Reactive, our default REST layer, does not require the use of Hibernate Reactive.
It is perfectly valid to use RESTEasy Reactive with Hibernate ORM,

Check warning on line 23 in docs/src/main/asciidoc/hibernate-reactive-panache.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.SentenceLength] Try to keep sentences to an average of 32 words or fewer. Raw Output: {"message": "[Quarkus.SentenceLength] Try to keep sentences to an average of 32 words or fewer.", "location": {"path": "docs/src/main/asciidoc/hibernate-reactive-panache.adoc", "range": {"start": {"line": 23, "column": 1}}}, "severity": "INFO"}
and if you do not need high-concurrency, or are not accustomed to the reactive paradigm, it is recommended to use Hibernate ORM.
====

== First: an example

What we're doing in Panache allows you to write your Hibernate Reactive entities like this:
Expand Down Expand Up @@ -685,7 +695,7 @@
----
import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
@RegisterForReflection
public class RaceWeight {
public final String race;
public final Double weight
Expand Down Expand Up @@ -736,7 +746,7 @@
Also make sure to wrap methods that modify the database or involve multiple queries (e.g. `entity.persist()`) within a transaction.
You can annotate a CDI business method that returns `Uni` with the `@WithTransaction` annotation.
The method will be intercepted and the returned `Uni` is triggered within a transaction boundary.
Alternatively, you can use the `Panache.withTransaction()` method for the same effect.
Alternatively, you can use the `Panache.withTransaction()` method for the same effect.

IMPORTANT: You cannot use the `@Transactional` annotation with Hibernate Reactive for your transactions: you must use `@WithTransaction`, and your annotated method must return a `Uni` to be non-blocking.

Expand Down Expand Up @@ -871,9 +881,9 @@

@Test
@RunOnVertxContext
public void testEntity(TransactionalUniAsserter asserter) {
public void testEntity(TransactionalUniAsserter asserter) {
asserter.execute(() -> new MyEntity().persist()); <1>
asserter.assertEquals(() -> MyEntity.count(), 1l); <2>
asserter.assertEquals(() -> MyEntity.count(), 1l); <2>
asserter.execute(() -> MyEntity.deleteAll()); <3>
}
}
Expand Down Expand Up @@ -1062,7 +1072,7 @@
@RunOnVertxContext // <1>
@Test
public void testPanacheRepositoryMocking(UniAsserter asserter) { // <2>

// Mocked classes always return a default value
asserter.assertEquals(() -> mockablePersonRepository.count(), 0l);

Expand Down Expand Up @@ -1091,7 +1101,7 @@
});
asserter.assertThat(() -> mockablePersonRepository.findById(12l), p -> Assertions.assertSame(p, asserter.getData(key)));
asserter.assertNull(() -> mockablePersonRepository.findById(42l));

// Mock throwing
asserter.execute(() -> Mockito.when(mockablePersonRepository.findById(12l)).thenThrow(new WebApplicationException()));
asserter.assertFailedWith(() -> {
Expand All @@ -1113,9 +1123,9 @@
Mockito.verify(mockablePersonRepository).persist(Mockito.<Person> any());
Mockito.verifyNoMoreInteractions(mockablePersonRepository);
});

// IMPORTANT: We need to execute the asserter within a reactive session
asserter.surroundWith(u -> Panache.withSession(() -> u));

Check warning on line 1128 in docs/src/main/asciidoc/hibernate-reactive-panache.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'verify' rather than 'Make sure' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'verify' rather than 'Make sure' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/hibernate-reactive-panache.adoc", "range": {"start": {"line": 1128, "column": 40}}}, "severity": "WARNING"}
}
}
----
Expand Down
11 changes: 10 additions & 1 deletion docs/src/main/asciidoc/hibernate-reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
:reactive-doc-url-prefix: https://hibernate.org/reactive/documentation/1.1/reference/html_single/#getting-started
:extension-status: preview


link:https://hibernate.org/reactive/[Hibernate Reactive] is a reactive API for Hibernate ORM, supporting non-blocking database drivers
and a reactive style of interaction with the database.

[NOTE]
====
Hibernate Reactive is not a replacement for xref:hibernate-orm.adoc[Hibernate ORM] or the future of Hibernate ORM.
It is a different stack tailored for reactive use cases where you need high-concurrency.

Also, using RESTEasy Reactive, our default REST layer, does not require the use of Hibernate Reactive.
It is perfectly valid to use RESTEasy Reactive with Hibernate ORM,

Check warning on line 21 in docs/src/main/asciidoc/hibernate-reactive.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.SentenceLength] Try to keep sentences to an average of 32 words or fewer. Raw Output: {"message": "[Quarkus.SentenceLength] Try to keep sentences to an average of 32 words or fewer.", "location": {"path": "docs/src/main/asciidoc/hibernate-reactive.adoc", "range": {"start": {"line": 21, "column": 1}}}, "severity": "INFO"}
and if you do not need high-concurrency, or are not accustomed to the reactive paradigm, it is recommended to use Hibernate ORM.
====

[NOTE]
====
Hibernate Reactive works with the same annotations and most of the configuration described in the
Expand Down