Skip to content

Commit 5170561

Browse files
committed
split a rant into two rants
Signed-off-by: Gavin King <[email protected]>
1 parent 79a6af6 commit 5170561

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -421,32 +421,22 @@ In a real program, persistence logic like the code shown above is usually interl
421421
Therefore, many developers quickly—even _too quickly_, in our opinion—reach for ways to isolate the persistence logic into some sort of separate architectural layer.
422422
We're going to ask you to suppress this urge for now.
423423

424-
[TIP]
425-
====
426-
The _easiest_ way to use Hibernate is to call the `Session` or `EntityManager` directly.
427-
If you're new to Hibernate, frameworks which wrap JPA are quite likely to make your life more difficult.
428-
====
429-
430424
We prefer a _bottom-up_ approach to organizing our code.
431425
We like to start thinking about methods and functions, not about architectural layers and container-managed objects.
432426

433427
.Rethinking the persistence layer
434428
****
435429
When we wrote _An Introduction to Hibernate 6_, the predecessor of this document, we broke with a long practice of remaining agnostic in debates over application architecture.
436-
Into the vacuum created by our agnosticism had poured a wealth of advice which tended to encourage over-engineering and violation of the First Commandment of software engineering: _Don't Repeat Yourself._
430+
Into the vacuum created by our agnosticism had poured a deluge of advice which tended to encourage over-engineering and violation of the First Commandment of software engineering: _Don't Repeat Yourself._
437431
We felt compelled to speak up for a more elementary approach.
438432
439-
At that time, we were especially frustrated with the limitations of popular frameworks which claimed to simplify the use of JPA by wrapping and hiding the `EntityManager`.
440-
In our considered opinion, such frameworks typically made JPA harder to use.
441-
442-
The birth of the Jakarta Data specification has obsoleted our arguments against repositories, along with the older frameworks which were the source of our frustration.
443-
Jakarta Data--as realized by Hibernate Data Repositories--offers a clean but very flexible way to organize code, along with much better compile-time type safety, without getting in the way of direct use of the Hibernate `StatelessSession`.
444-
445-
That said, we reiterate our preference for design which emerges organically from the code itself, via a process of refactoring and iterative abstraction.
433+
Here, we reiterate our preference for design which emerges organically from the code itself, via a process of refactoring and iterative abstraction.
446434
The Extract Method refactoring is a far, far more powerful tool than drawing boxes and arrows on whiteboards.
447-
In particular, we hereby give you permission to write code which mixes business logic with persistence logic within the same architectural layer--every architectural layer comes with a high cost in boilerplate, and in many contexts a separate persistence layer is simply unnecessary.
435+
436+
In particular, we hereby give you permission to write code which mixes business logic with persistence logic within the same architectural layer.
437+
Every architectural layer comes with a high cost in boilerplate, and in many contexts a separate persistence layer is simply unnecessary.
448438
// In 2025 it no longer makes sense to shoehorn every system into an architecture advocated by some book written in the early 2000's.
449-
Both of the following architectures are allowed, and each has its place:
439+
Both of the following architectures represent allowed points within the design space:
450440
451441
image::images/architecture.png[API overview,pdfwidth="100%",width=1100,align="center"]
452442
@@ -584,7 +574,7 @@ interface Queries {
584574
----
585575

586576
Then Hibernate Processor automatically produces an implementation of the method annotated `@HQL` in a class named `Queries_`.
587-
We can call it just like we called our handwritten version:
577+
We can call it just like we were previously calling our handwritten version:
588578

589579
[source,java]
590580
----
@@ -636,12 +626,21 @@ Alternatively, if CDI isn't available, we may directly instantiate the generated
636626

637627
[TIP]
638628
====
639-
The Jakarta Data specification now formalizes this approach using standard annotations, and our implementation of this specification, Hibernate Data Repositories, is built into Hibernate Processor.
629+
The Jakarta Data specification now formalizes this approach using standard annotations, and our implementation of this specification, Hibernate Data Repositories, is built into <<generator,Hibernate Processor>>.
640630
You probably already have it available in your program.
641631
642632
Unlike other repository frameworks, Hibernate Data Repositories offers something that plain JPA simply doesn’t have: full compile-time type safety for your queries. To learn more, please refer to link:{doc-data-repositories-url}[Introducing Hibernate Data Repositories].
643633
====
644634

635+
.Why we changed our mind about repositories
636+
****
637+
At the time we wrote _An Introduction to Hibernate 6_, we were especially frustrated with the limitations of popular frameworks which claimed to simplify the use of JPA by wrapping and hiding the `EntityManager`.
638+
In our considered opinion, such frameworks typically made JPA harder to use, sometimes misleading users into misuse of the technology.
639+
640+
The birth of the Jakarta Data specification has obsoleted our arguments against repositories, along with the older frameworks which were the source of our frustration.
641+
Jakarta Data--as realized by Hibernate Data Repositories--offers a clean but very flexible way to organize code, along with much better compile-time type safety, without getting in the way of direct use of the `StatelessSession`.
642+
****
643+
645644
Now that we have a rough picture of what our persistence logic might look like, it's natural to ask how we should test our code.
646645

647646
[[testing]]
@@ -679,6 +678,7 @@ configuration.property(PersistenceConfiguration.SCHEMAGEN_DATABASE_ACTION,
679678
----
680679

681680
Alternatively, we may use the new link:{doc-javadoc-url}org/hibernate/relational/SchemaManager.html[`SchemaManager`] API to export the schema, just as we did <<main-hibernate,above>>.
681+
This option is especially convenient when writing tests.
682682

683683
[source,java]
684684
----

0 commit comments

Comments
 (0)