Course Summary
Advanced Hibernate Training course is designed to push students' OR/M skills to the next level. We skip the basic introduction of what Hibernate is and how to set up the basing mappings, and we move straight to the advanced topics, such as: filters, named queries, complex associations and mappings, advanced HQL, searching by example, Criteria API, transactions, versioning, fetching strategies, performance tuning, and best practices.Duration
3 days.
Objectives
- Understand Hibernate search capabilities: named queries, searching by example, Criteria API, advanced HQL, filtering, etc.
- Be able to model complex entity relationships: one-to-one, many-to-one, one-to-many, many-to-many, bidirectional, etc.
- Learn how to protect the state of your data through locking (e.g. versioning) and transactions
- Be able to tune the performance of your Hibernate code through optimized fetching strategies and caching.
- Learn how to diagnose and troubleshoot problems in your Hibernate code (e.g. the infamous LazyInitializationException)
- Be able to follow best practices in designing, writing, maintaining, and testing your Hibernate code
Audience
Students must have solid understanding of the Java language and be familiar with the Hibernate fundamentals, such as simple mappings, basic configuration, basic HQL, and Hibernate's Session API.
Previous exposure to Java EE, and SQL can be helpful.
Instructors
Additionally Martin has been producing electronic music for the last few years using Ableton Live. He has released two albums and has been playing his music live around the US and at festivals such as the Coachella, Shambhala and Burning Man festivals. Martin is currently working on a revolutionary open source music standard, to produce a platform for musicians to share and contribute to their art using the principals of open source software. Martin also teaches digital music production with tools such as Ableton Live and Cubase.
Martin has several real estate projects in progress in the Nicoya Peninsula in Costa Rica where he purchased large tracts of land several years ago and has begun developing infrastructure and reselling subdivisions. The ultimate goal in this project is to develop a 50 acre nature preservation around a man made reservoir, for the protection and preservation of indigenous animal and bird species that live in these coastal regions. More about Martin Folb...
My work with some of the world's most successful corporations has given me deep insight into the effective application of appropriate software tools and techniques in today's commercial environment.
My overall strengths include excellent communication and training skills, substantial knowledge and experience of the Java platform and XML technologies, proven judgement in the selection of emerging technologies, and an intelligent, mature approach to any new challenge.
I continue to invest heavily in keeping my knowledge and skills up to date in Java and XML for the enterprise, the relevant programming techniques and libraries, system architectures, and applications. I have retained an enthusiasm for the technical subjects I teach, which has often been commented upon in course evaluations. More about Michael Callaghan...
Additional Notes
Depending on the student needs, this class can focus on JPA/Annotation-style (preferred) or XML-based Hibernate mappings.
Hibernate™ is a registered trademark of Red Hat, Inc. Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. Marakana is not affiliated with these companies.
Marakana.com Runs on Java using Hibernate

Marakana.com is written in Java using Spring and Hibernate frameworks. We deploy it on Apache Tomcat Application Server. Both Marakana Spark and Apache Tomcat are Java applications and thus run on Java Virtual Machine. Spark uses MySQL database for persistence. Our operating system of choice is Ubuntu Linux, for security and reliability reasons. So we practice what we teach. You will learn from real developers.
Outline
Hibernate - Revisited
- Revisit the role Hibernate plays in our applications
- Revisit JPA
- Entity Manager
- Getting started with a simple Hibernate application
- Configuration
- API
- Mapping a simple class
- XML vs Annotations
- Common type mappings
- Inserting and updating
- Retrieving persistent objects
Advanced Property and Relationship Mappings
- Mapping advanced Java data types
- Mapping inter-entity relationships
- One to one, one to many, many to one, many to many
- Parent - child
- Collections
- Bidirectional
- Cascading Operations
- Transitive persistence
- Lazy and eager loading
- Collections of value objects
- Modeling a set of simple values
- Mapping collections of components
- Mapping inheritance
- Polymorphic support
- Exploring pros and cons of different strategies
- Single table
- Table per subclass
- Table per concrete class
The Persistance Lifecycle
- Hibernate Object States
- Transient, Persistent, Detached, Removed
- Transitions between states
- Persistance Context (Session)
- Lifecycle
- Acquiring a Session
- Session per request
- Session Propagation
- As Cache
- Synchronization with the database
- Flushing
- Object Identity
Protecting Data
- Transactions in Hibernate
- Lifecycle
- Demarcation
- API
- Optimistic vs. Pessimistic locking
- Versioning
- Integrating with external transaction managers
- Managed environment
Finding Your Data
- Simple "searching" by ID (Session API)
- Advanced HQL
- Revisited (syntax and API)
- Parameters
- Joins
- Named queries
- Functions (e.g. aggregate)
- Projections (tuples)
- Searching by example
- Native queries
- Criteria API
- Uses
- Restrictions
- Associations
- Ordering
- Fetching
- Filters
- Defining and attaching filters
- Using filters
- Mapping filters to a set
- Collection filters
Tuning Your Code
- Fetching strategies: lazy, eager, batch, sub-query loading
- Caching
- Second-level Cache
- Query Caching
- Data-appropriate caching
- Cache Providers
- Cache Configuration
- Managing caches
- Query Efficiency
- N+1 Select Problem
- Design Considerations
- Long conversations
- Session-per-conversation
- Open Session In View Pattern
Best Practices
- Entity identity: implementing equals() and hashCode()
- Designing your DAO layer
- Troubleshooting problems
- Testing your DAO code
- Logging
- Hibernate Toolset
- Installing
- Class Diagram
- HQL Editor
- Query Results
- SQL Preview
- Q&A