![](https://csdnimg.cn/release/download_crawler_static/9560616/bg12.jpg)
xvii
Preface
Since its inception, the Spring Framework has gradually changed the rules of application development in the
Java community. This book is the ideal guide and teaching companion for developers interested in learning
about the Spring Framework and how it can be leveraged to build persistence-driven applications using
Hibernate, one of the most popular Java persistence frameworks today. Spring Persistence with Hibernate
gets you rolling with fundamental Spring concepts, as well as proven design patterns for integrating
persistence into your applications.
Many of the lessons illustrated in this book were culled from years of practical experience building
scalable, high-volume web applications using Spring and Hibernate. One of the details that stands out in
our joint experience is the importance and benefit of learning through hands-on experience. To this end, we
will build a real-world application that utilizes Spring 4, Hibernate 5, Spring-Data, JPA 2.1, and Query-DSL.
We firmly believe that learning about Spring and Hibernate implies far more than simply understanding the
respective APIs of each framework. To be able to effectively develop with these two amazing technologies,
it is necessary to understand the design patterns and best practices for getting the most from these
frameworks, and building on them in a consistent, proven manner. We hope that this book teaches you more
than just how to use Spring and Hibernate together. Our goal is to channel the development experience,
lessons, and best practices we’ve seen work successfully in our experience, so that you can apply these skills
and tools in your own applications.
Throughout these pages, we introduce core Hibernate fundamentals, demonstrating how the
framework can be best utilized within a Spring context. We start with foundational concepts, such as
strategies for developing an effective domain model and DAO layer, and then move into querying techniques
using HQL, JPQL, Spring-Data, and Query-DSL (a powerful framework that offers a flexible, generic, and
type-safe query abstraction). After fundamental concepts are introduced, we move on to more advanced
topics, such as fetching and caching strategies. We also illustrate several approaches for architecting a
transactional service facade. Both programmatic and declarative transactions are examined, showcasing the
benefits of using Spring for expressing transactional semantics.
Spring Persistence with Hibernate also introduces JPA, covering its history and the ways in which
Hibernate influenced its development. We discuss the benefits of following the JPA standard, as well as
when it makes sense to utilize Hibernate-specific features. The book also examines different strategies and
best-practices for architecting your persistence tier, such as illustrating the differences between the DAO and
Active Record patterns. Throughout this book, we explore topics related to concurrency/optimistic locking,
Hibernate Session state, caching approaches, and transaction management.
The last part of the book introduces several advanced techniques, important for working with enterprise
Spring/Hibernate applications. We illustrate some of the pitfalls with integrating legacy databases, as well
as best practices for developing REST web services, handling Hibernate proxies and lazy collections, and
proven patterns that will prove valuable for any database-driven project running on the JVM.