Java persistence with Spring Data and Hibernate
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 compar...
Other Authors: | |
---|---|
Format: | eBook |
Language: | Inglés |
Published: |
Shelter Island, NY :
Manning Publications Co
[2023]
|
Subjects: | |
See on Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009730928606719 |
Table of Contents:
- Intro
- inside front cover
- Java Persistence with Spring Data and Hibernate
- Copyright
- dedication
- brief contents
- contents
- front matter
- 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
- 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
- Summary
- 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
- Summary
- 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
- Summary
- 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
- Summary
- Part 2. Mapping strategies
- 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
- Summary
- 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
- Summary
- 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
- Summary
- 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
- Summary
- 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
- Summary.
- Part 3. Transactional data processing
- 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
- Summary
- 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
- Summary
- 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
- Summary
- 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
- Summary
- Part 4. Building Java persistence applications with Spring
- 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
- Summary
- 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.