You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/src/main/asciidoc/introduction/Introduction.adoc
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -421,32 +421,22 @@ In a real program, persistence logic like the code shown above is usually interl
421
421
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.
422
422
We're going to ask you to suppress this urge for now.
423
423
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
-
430
424
We prefer a _bottom-up_ approach to organizing our code.
431
425
We like to start thinking about methods and functions, not about architectural layers and container-managed objects.
432
426
433
427
.Rethinking the persistence layer
434
428
****
435
429
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._
437
431
We felt compelled to speak up for a more elementary approach.
438
432
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.
446
434
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.
448
438
// 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:
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:
588
578
589
579
[source,java]
590
580
----
@@ -636,12 +626,21 @@ Alternatively, if CDI isn't available, we may directly instantiate the generated
636
626
637
627
[TIP]
638
628
====
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>>.
640
630
You probably already have it available in your program.
641
631
642
632
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].
643
633
====
644
634
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
+
645
644
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.
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.
0 commit comments