![]()
Table of Contents
Mastering Hibernate
Credits
About the Author
About the Reviewers
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Entity and Session
Why this book?
Quick Hibernate
Working with a session
Session internals
Contextual session
Session per request
Session per conversation
Session per operation
Stateless session
Entity
Entity lifecycle
Types of entities
Identity crisis
Beyond JPA
Proxy objects
Batch processing
Manual batch management
Setting batch size
Using stateless session
Summary
2. Advanced Mapping
Mapping concepts
Instances and rows
Annotation versus XML
Owning entity
Value mapping
JPA ID generation
Hibernate ID generation
Composite ID
Association cardinality
One-to-one associations
One-to-many associations
Many-to-one associations
Many-to-many associations
Self-referencing tables
Cascade operations
Inheritance
Single table strategy
Table per class strategy
Joined strategy
Enumeration and custom data type
Enumerated type
Custom data type mapping
Summary
3. Working with Annotations
Mapping and association
@Any and @ManyToAny
@MapsId
@Fetch
@OrderBy
@ElementCollection and @CollectionTable
Behavior
@Cache
@Access
@Cascade
@CreationTimestamp and @UpdateTimestamp
@Filter and @FilterDef
@Immutable
@Loader
@NotFound
@SortComparator and @SortNatural
SQL/DDL modifier
@Check
@ColumnDefault
@ColumnTransformer
@DynamicInsert and @DynamicUpdate
@Formula
@SelectBeforeUpdate
@SQLDelete and @Where
@SQLInsert and @SQLUpdate
@SubSelect and @Synchronize
@WhereJoinTable
@NaturalId
Summary
4. Advanced Fetching
Fetching strategy
The JOIN fetch mode
The SELECT fetch mode
The SUBSELECT fetch mode
Batch fetching
Hibernate Query Language
Fetch queries
Delete and update
Join
Native SQL
Scalar query
Entity query
Criteria objects
Filters
Pagination
Summary
5. Hibernate Cache
Cache structure
Cache scope
First-level cache
Second-level cache
Cache provider interface
Ehcache implementation
Cache configuration
Query cache
Caching benefits and pitfalls
Caching strategies
Read only
Non-strict read write
Read-write
Transactional
Object identity
Managing the cache
Remove cached entities
Cache modes
Cache metrics
Summary
6. Events, Interceptors, and Envers
Services
Service loader
Service registry
The OSGi model
Events
Event listener
Registering listeners
Interceptors
Database trigger
Event or interceptor
Envers
Configuration
Strategy
Fetching revisions
Summary
7. Metrics and Statistics
Statistical data types
Session
Entity
Collection
Query
Cache
Statistics via JMX
Introduction to JMX
Using JMX with Hibernate
Summary
8. Addressing Architecture
Architecture matters
Transaction management
Local transactions
The Java Transaction API
Compensating transactions
Concurrency
Isolation levels
Locking
User lock
Scalability
Clustering
Database shards
Configuration
Sharded session factory
Shard strategy
Shard ID generation
Performance
Lazy loading
Fetch mode
Batch processing
Caching
Stateless session
Legacy application
Reverse engineering
Modernization
The Cloud strategy
Licensing
Multi-tenancy
Summary
9. EJB and Spring Context
Deployment
Configuration
Resource
Transaction
Hibernate libraries
EJB
Persistence unit
Server resources
Entity manager
Transaction
Hibernate session
Spring
Configuration
Transaction management
Data source
Session factory
Summary
Index
![]()
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: May 2016
Production reference: 1100516
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78217-533-9
www.packtpub.com
![]()
Author
Ramin Rad
Reviewers
Luca Masini
Sherwin John Calleja-Tragura
Aurélie Vache
Commissioning Editor
Neil Alexander
Acquisition Editor
Reshma Raman
Content Development Editor
Zeeyan Pinheiro
Technical Editor
Pranjali Mistry
Copy Editor
Pranjali Chury
Project Coordinator
Francina Pinto
Proofreader
Safis Editing
Indexer
Rekha Nair
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
![]()
Ramin Rad has been working as a software professional for the last 20 years, living in Washington DC area. He studied mathematics and computer science in the academic world, and he cares deeply for the art of software development.
He is also a musician, a guitarist, who performs regularly in the DC area and beyond. His artistic side is significant because he believes that writing software is more art than science, following the philosophy of the likes of Donald Knuth, who wrote the Art of Computer Programming series.
Currently, he is a director and a solution architect at a large international software product and services company, focusing on enterprise, mobile, and cloud-based solutions.
![]()
Luca Masini is a senior software engineer and architect. He started off as a game developer for Commodore 64 (Football Manager) and Commodore Amiga (Ken il guerriero). He soon converted to object oriented programming, and for that, from its beginning in 1995, he was attracted by the Java language.
Following his passion, he worked as a consultant for major Italian banks, developing and integrating the main software projects for which he has often taken technical leadership. He encouraged the adoption Java Enterprise in environments where COBOL was the flagship platform, converting them from mainframe centric to distributed.
He then shifted his focus toward open source, starting from Linux and then m...