Skip to content

Commit

Permalink
Add a note about HR not being a replacement for ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Sep 19, 2023
1 parent f974941 commit a1a2485
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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 @@ breadth of an Object Relational Mapper allowing you to access your database over
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,
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 @@ matching the values returned by the select clause:
----
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 @@ NOTE: Note that a Panache entity may not be used from a blocking thread. See als
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 @@ public class SomeTest {
@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 @@ public class PanacheFunctionalityTest {
@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 @@ public class PanacheFunctionalityTest {
});
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,7 +1123,7 @@ public class PanacheFunctionalityTest {
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));
}
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 @@ include::_attributes.adoc[]
: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,
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

0 comments on commit a1a2485

Please sign in to comment.