Java Persistence with Spring Data and Hibernate

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Master Java persistence using the industry-leading tools Spring Data and Hibernate. In Java Persistence with Spring Data and Hibernate you will learn: • Mapping persistent classes, value types, and inheritance • Mapping collections and entity associations • Processing transactions with Spring Data and Hibernate • Creating fetch plans, strategies, and profiles • Filtering data • Building Spring Data REST projects • Using Java persistence with non-relational databases • Querying JPA with QueryDSL • Testing Java persistence applications Java Persistence with Spring Data and Hibernate teaches you the ins-and-outs of Java persistence with hands-on examples using Spring Data, JPA, and Hibernate. The book carefully analyzes the capabilities of the major Java persistence tools, and guides you through the most common use cases. By comparing and contrasting the alternatives, you’ll find it easy to choose the right tool choice for your applications. You’ll learn how to make and utilize mapping strategies, about the different approach to transactions for both Hibernate and Spring Data, and even how to efficiently test Java persistence applications. The practical techniques are demonstrated with both relational and non-relational databases. Forewords by Dmitry Aleksandrov and Mohamed Taman. About the technology Effectively managing application data is essential for any serious application. Spring Data and Hibernate bridge the gap between object-oriented code and relational data stores, radically simplifying Java persistence. By implementing the Java Persistence API (JPA) standard, these powerful tools help you avoid common bugs related to state and application data storage. About the book Java Persistence with Spring Data and Hibernate explores Java persistence using industry-standard tools. Hands-on examples introduce object-relational mapping and guide you through different mapping strategies to suit your needs. Covering transactions, persistent application testing, and non-relational databases, this book is your go-to resource for managing data in Java applications. What's inside • Mapping persistent classes, value types, and inheritance • Creating fetch plans, strategies, and profiles • Building Spring Data REST projects • Querying JPA with QueryDSL About the reader For intermediate Java programmers. About the author Catalin Tudose has more than 20 years of experience in the Java community. Christian Bauer, Gavin King, and Gary Gregory are the authors of Java Persistence with Hibernate, Second Edition, on which this book is based.

Author(s): Catalin Tudose
Edition: 1
Publisher: Manning Publications
Year: 2023

Language: English
Commentary: Publisher's PDF
Pages: 616
City: Shelter Island, NY
Tags: Java; Concurrency; Relational Databases; MongoDB; Transactions; Persistence; Spring Data; Hibernate; Object/Relational Mapping; Jakarta Persistence API

Java Persistence with Spring Data and Hibernate
brief contents
contents
forewords
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A road map
About the code
liveBook discussion forum
about the author
authors of Java Persistence with Hibernate, Second Edition
about the cover illustration
Part 1: Getting started with ORM
Chapter 1: Understanding object/ relational persistence
1.1 What is persistence?
1.1.1 Relational databases
1.1.2 Understanding SQL
1.1.3 Using SQL in Java
1.2 The paradigm mismatch
1.2.1 The problem of granularity
1.2.2 The problem of inheritance
1.2.3 The problem of identity
1.2.4 The problem of associations
1.2.5 The problem of data navigation
1.3 ORM, JPA, Hibernate, and Spring Data
Chapter 2: Starting a project
2.1 Introducing Hibernate
2.2 Introducing Spring Data
2.3 “Hello World” with JPA
2.3.1 Configuring a persistence unit
2.3.2 Writing a persistent class
2.3.3 Storing and loading messages
2.4 Native Hibernate configuration
2.5 Switching between JPA and Hibernate
2.6 “Hello World” with Spring Data JPA
2.7 Comparing the approaches of persisting entities
Chapter 3: Domain models and metadata
3.1 The example CaveatEmptor application
3.1.1 A layered architecture
3.1.2 Analyzing the business domain
3.1.3 The CaveatEmptor domain model
3.2 Implementing the domain model
3.2.1 Addressing leakage of concerns
3.2.2 Transparent and automated persistence
3.2.3 Writing persistence-capable classes
3.2.4 Implementing POJO associations
3.3 Domain model metadata
3.3.1 Annotation-based metadata
3.3.2 Applying constraints to Java objects
3.3.3 Externalizing metadata with XML files
3.3.4 Accessing metadata at runtime
Chapter 4: Working with Spring Data JPA
4.1 Introducing Spring Data JPA
4.2 Starting a new Spring Data JPA project
4.3 First steps for configuring a Spring Data JPA project
4.4 Defining query methods with Spring Data JPA
4.5 Limiting query results, sorting, and paging
4.6 Streaming results
4.7 The @Query annotation
4.8 Projections
4.9 Modifying queries
4.10 Query by Example
Part 2: Mapping strategies
Chapter 5: Mapping persistent classes
5.1 Understanding entities and value types
5.1.1 Fine-grained domain models
5.1.2 Defining application concepts
5.1.3 Distinguishing entities and value types
5.2 Mapping entities with identity
5.2.1 Understanding Java identity and equality
5.2.2 A first entity class and mapping
5.2.3 Selecting a primary key
5.2.4 Configuring key generators
5.2.5 Identifier generator strategies
5.3 Entity-mapping options
5.3.1 Controlling names
5.3.2 Dynamic SQL generation
5.3.3 Making an entity immutable
5.3.4 Mapping an entity to a subselect
Chapter 6: Mapping value types
6.1 Mapping basic properties
6.1.1 Overriding basic property defaults
6.1.2 Customizing property access
6.1.3 Using derived properties
6.1.4 Transforming column values
6.1.5 Generated and default property values
6.1.6 The @Temporal annotation
6.1.7 Mapping enumerations
6.2 Mapping embeddable components
6.2.1 The database schema
6.2.2 Making classes embeddable
6.2.3 Overriding embedded attributes
6.2.4 Mapping nested embedded components
6.3 Mapping Java and SQL types with converters
6.3.1 Built-in types
6.3.2 Creating custom JPA converters
6.3.3 Extending Hibernate with UserTypes
Chapter 7: Mapping inheritance
7.1 Table per concrete class with implicit polymorphism
7.2 Table per concrete class with unions
7.3 Table per class hierarchy
7.4 Table per subclass with joins
7.5 Mixing inheritance strategies
7.6 Inheritance of embeddable classes
7.7 Choosing a strategy
7.8 Polymorphic associations
7.8.1 Polymorphic many-to-one associations
7.8.2 Polymorphic collections
Chapter 8: Mapping collections and entity associations
8.1 Sets, bags, lists, and maps of value types
8.1.1 The database schema
8.1.2 Creating and mapping a collection property
8.1.3 Selecting a collection interface
8.1.4 Mapping a set
8.1.5 Mapping an identifier bag
8.1.6 Mapping a list
8.1.7 Mapping a map
8.1.8 Sorted and ordered collections
8.2 Collections of components
8.2.1 Equality of component instances
8.2.2 Set of components
8.2.3 Bag of components
8.2.4 Map of component values
8.2.5 Components as map keys
8.2.6 Collection in an embeddable component
8.3 Mapping entity associations
8.3.1 The simplest possible association
8.3.2 Making it bidirectional
8.3.3 Cascading state
Chapter 9: Advanced entity association mappings
9.1 One-to-one associations
9.1.1 Sharing a primary key
9.1.2 The foreign primary key generator
9.1.3 Using a foreign key join column
9.1.4 Using a join table
9.2 One-to-many associations
9.2.1 Considering one-to-many bags
9.2.2 Unidirectional and bidirectional list mappings
9.2.3 Optional one-to-many with a join table
9.2.4 One-to-many association in an embeddable class
9.3 Many-to-many and ternary associations
9.3.1 Unidirectional and bidirectional many-to-many associations
9.3.2 Many-to-many with an intermediate entity
9.3.3 Ternary associations with components
9.4 Entity associations with maps
9.4.1 One-to-many with a property key
9.4.2 Key/value ternary relationship
Part 3: Transactional data processing
Chapter 10: Managing data
10.1 The persistence lifecycle
10.1.1 Entity instance states
10.1.2 The persistence context
10.2 The EntityManager interface
10.2.1 The canonical unit of work
10.2.2 Making data persistent
10.2.3 Retrieving and modifying persistent data
10.2.4 Getting a reference
10.2.5 Making data transient
10.2.6 Refreshing data
10.2.7 Replicating data
10.2.8 Caching in the persistence context
10.2.9 Flushing the persistence context
10.3 Working with detached state
10.3.1 The identity of detached instances
10.3.2 Implementing equality methods
10.3.3 Detaching entity instances
10.3.4 Merging entity instances
Chapter 11: Transactions and concurrency
11.1 Transaction essentials
11.1.1 ACID attributes
11.1.2 Database and system transactions
11.2 Controlling concurrent access
11.2.1 Understanding database-level concurrency
11.2.2 Optimistic concurrency control
11.2.3 Explicit pessimistic locking
11.2.4 Avoiding deadlocks
11.3 Non-transactional data access
11.3.1 Reading data in auto-commit mode
11.3.2 Queuing modifications
11.4 Managing transactions with Spring and Spring Data
11.4.1 Transaction propagation
11.4.2 Transaction rollback
11.4.3 Transaction properties
11.4.4 Programmatic transaction definition
11.4.5 Transactional development with Spring and Spring Data
Chapter 12: Fetch plans, strategies, and profiles
12.1 Lazy and eager loading
12.1.1 Understanding entity proxies
12.1.2 Lazy persistent collections
12.1.3 Eager loading of associations and collections
12.2 Selecting a fetch strategy
12.2.1 The n+1 selects problem
12.2.2 The Cartesian product problem
12.2.3 Prefetching data in batches
12.2.4 Prefetching collections with subselects
12.2.5 Eager fetching with multiple SELECTs
12.2.6 Dynamic eager fetching
12.3 Using fetch profiles
12.3.1 Declaring Hibernate fetch profiles
12.3.2 Working with entity graphs
Chapter 13: Filtering data
13.1 Cascading state transitions
13.1.1 Available cascading options
13.1.2 Transitive detachment and merging
13.1.3 Cascading refresh
13.1.4 Cascading replication
13.2 Listening to and intercepting events
13.2.1 JPA event listeners and callbacks
13.2.2 Implementing Hibernate interceptors
13.2.3 The core event system
13.3 Auditing and versioning with Hibernate Envers
13.3.1 Enabling audit logging
13.3.2 Creating an audit trail
13.3.3 Finding revisions
13.3.4 Accessing historical data
13.4 Dynamic data filters
13.4.1 Defining dynamic filters
13.4.2 Applying a dynamic filter
13.4.3 Enabling a dynamic filter
13.4.4 Filtering collection access
Part 4: Building Java persistence applications with Spring
Chapter 14: Integrating JPA and Hibernate with Spring
14.1 Spring Framework and dependency injection
14.2 JPA application using Spring and the DAO pattern
14.3 Generifying a JPA application that uses Spring and DAO
14.4 Hibernate application using Spring and the DAO pattern
14.5 Generifying a Hibernate application that uses Spring and DAO
Chapter 15: Working with Spring Data JDBC
15.1 Creating a Spring Data JDBC project
15.2 Working with queries in Spring Data JDBC
15.2.1 Defining query methods with Spring Data JDBC
15.2.2 Limiting query results, sorting, and paging
15.2.3 Streaming results
15.2.4 The @Query annotation
15.2.5 Modifying queries
15.3 Modeling relationships with Spring Data JDBC
15.3.1 Modeling a one-to-one relationship with Spring Data JDBC
15.3.2 Modeling embedded entities with Spring Data JDBC
15.3.3 Modeling a one-to-many relationship with Spring Data JDBC
15.3.4 Modeling a many-to-many relationship with Spring Data JDBC
Chapter 16: Working with Spring Data REST
16.1 Introducing REST applications
16.2 Creating a Spring Data REST application
16.3 Using ETags for conditional requests
16.4 Limiting access to repositories, methods, and fields
16.5 Working with REST events
16.5.1 Writing an AnnotatedHandler
16.5.2 Writing an ApplicationListener
16.6 Using projections and excerpts
Part 5: Building Java persistence applications with Spring
Chapter 17: Working with Spring Data MongoDB
17.1 Introducing MongoDB
17.2 Introducing Spring Data MongoDB
17.3 Using MongoRepository to access a database
17.3.1 Defining query methods with Spring Data MongoDB
17.3.2 Limiting query results, sorting, and paging
17.3.3 Streaming results
17.3.4 The @Query annotation
17.4 Query by Example
17.5 Referencing other MongoDB documents
17.6 Using MongoTemplate to access a database
17.6.1 Configuring access to the database through MongoTemplate
17.6.2 Executing CRUD operations using MongoTemplate
Chapter 18: Working with Hibernate OGM
18.1 Introducing Hibernate OGM
18.2 Building a simple MongoDB Hibernate OGM application
18.2.1 Configuring the Hibernate OGM application
18.2.2 Creating the entities
18.2.3 Using the application with MongoDB
18.3 Switching to the Neo4j NoSQL database
Part 6: Writing queries and testing Java persistence applications
Chapter 19: Querying JPA with Querydsl
19.1 Introducing Querydsl
19.2 Creating a Querydsl application
19.2.1 Configuring the Querydsl application
19.2.2 Creating the entities
19.2.3 Creating the test data to query
19.3 Querying a database with Querydsl
19.3.1 Filtering data
19.3.2 Ordering data
19.3.3 Grouping data and working with aggregates
19.3.4 Working with subqueries and joins
19.3.5 Updating entities
19.3.6 Deleting entities
Chapter 20: Testing Java persistence applications
20.1 Introducing the test pyramid
20.2 Creating the persistence application to test
20.3 Using the Spring TestContext Framework
20.4 The @DirtiesContext annotation
20.5 @Transactional execution
20.6 The @BeforeTransaction and @AfterTransaction annotations
20.7 Working with Spring profiles
20.8 Working with test execution listeners
appendix A: Maven
A.1 Convention over configuration
A.2 Strong dependency management
A.3 Maven build lifecycles
A.4 Plugin-based architecture
A.5 The Maven project object model (POM)
A.6 Installing Maven
appendix B: Spring Data JPA keyword usage
appendix C: Spring Data JDBC keyword usage
appendix D: Spring Data MongoDB keyword usage
references
index
Symbols
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X