
Learn to simplify Java persistence with Hibernate and JPA, from object-relational mapping basics to advanced topics, using practical examples, runtime insights, and performance best practices.
Explore the object-relational impedance mismatch between Java object graphs and relational tables, detailing granularity, inheritance, identity, associations, and data navigation mismatches, with practical SQL join strategies.
Explore object relational mapping with a bookstore example, mapping Java objects to MySQL tables and persisting a book object graph. See how ORM reduces JDBC and SQL boilerplate.
Install the MySQL community server with the MSI installer. Set a root password and create a bookstore database with publisher, book, and chapter tables using the command-line client; explore HeidiSQL.
Develop, persist, and retrieve a book object graph in a MySQL bookstore database, compare JDBC-based ORM with Hibernate to address object-relational mismatch.
Practice object relational mapping by downloading and running the lab's source code, ensuring MySQL 5.6 compatibility, persisting the book object graph, and exploring impedance mismatch concepts.
Maps Java objects to relational tables and generates SQL for save, update, delete, and query operations, Hibernate acts as an object-relational mapping framework.
Learn how to persist a hello world message with Hibernate and JPA annotations, from session management and configuration to annotation-based entity mapping and auto-generated keys.
Explore Hibernate in action by persisting a Hello World message using both a legacy Hibernate mapping file and a JPA annotated entity, with a MySQL Hello World database.
Upgrade to Hibernate 5 by adopting the metadata-based SessionFactory and explicitly using the identity generation strategy, replacing the Hibernate 4 approach to resolve mapping exceptions and run without errors.
Ensure Java 11 compatibility with Hibernate six. Adopt Jakarta persistence and use Maven projects, identity strategy, and session factory metadata, noting deprecated methods and persist usage.
Hibernate 7 has been released; use Java 17 as the minimum version for the provided source code. The course remains valid, with added Hibernate 7 feature sessions and ongoing updates.
Explore how a hello world message progresses through transient, persistent, and detached states in a Hibernate and JPA session and transaction, with a primary key assigned.
Enable Hibernate logging to view internal workings and debugging information. Configure log for J with a properties file to control levels and reveal SQL and binding parameter values.
Activate hibernate statistics and info-level session logging to view internal session details, jdbc timing, and second-level caching in the lab; avoid enabling them in production.
Learn to manipulate objects with Hibernate by finding, updating, and deleting within transactions; understand automatic dirty checking, transaction commit, and the necessity of a no-arg constructor for entities.
Load a message by its ID, update its text via dirty checking, and delete it within a Hibernate session, illustrating persistent, managed, and removed states and transactional commit.
Persist the updated state of a detached message object by using the merge method to update the database. Note Hibernate 6 deprecates update and delete; use merge and remove.
Explore aggregation and composition by contrasting a band and its artists with a house and its rooms. See how the whole's destruction affects its parts, and whether parts are shared.
Differentiate entities and value types to see which objects carry a database identity, using a user with home and billing addresses as examples.
Map a component as an embeddable value inside an entity using the embedded and embeddable annotations, persisting address with default table/column mapping and optional overrides.
Explore entity versus value type decisions for addresses, identify value types and aggregate relationships, and learn Hibernate's create and create drop options for auto schema generation via a session factory.
Map the many-to-one relationship between student and guide using join column annotation and a guide_id foreign key. Configure Hibernate to persist and test the association.
Master cascading in Hibernate and JPA by persisting a student and its guide with a single operation. Learn how persist and remove cascades affect the whole object graph.
Demonstrates why cascading removal in a many-to-one relation can violate foreign key constraints, and shows how to detach the guide before deleting the student to avoid errors.
Explains bidirectional one-to-many relationships in Hibernate, owner vs inverse, mapped by, foreign keys, cascading persists, and helper methods to manage associations.
Compare unidirectional and bidirectional one-to-many mappings in Hibernate, showing how a unidirectional join table is created and why bidirectional mappings are preferred for performance.
Use the orphanRemoval attribute in a bidirectional one-to-many relationship to delete orphaned child records and prevent foreign key constraint violations during cascaded deletions.
Explore bidirectional one-to-one mapping between customer and passport, with the customer as owner using passport_id as a unique foreign key; apply cascade persist and Hibernate mappings for table creation.
Derive identifiers with maps id to share a primary key in one-to-one mappings, using a passport to customer example and simplifying bidirectional associations.
Explains mapping a bidirectional many-to-many relationship between movies and actors using a join table, with the movie entity as owner and the actor as inverse, and demonstrates cascading persists.
Explore configuring bi-directional many-to-many relationships in Hibernate by using a synchronization utility that updates both sides, ensuring join table reflects additions and removals of movies for actors.
Map Java enums to the employee status column using the enumerated annotation with enum type string, persisting full time, part time, and contract values, and retrieving employees with Hibernate.
Map enum values to custom database values using a JPA attribute converter to persist and retrieve statuses like full time to 100, part time to 200, and contract to 300.
Map enum values to custom values using Hibernate 7's enumerated value annotation, persisting full time, part time, and contract statuses as 100, 200, and 300.
Learn to map a collection of simple value types with element collection and collection table in Hibernate and JPA, enforcing a composite primary key to avoid duplicates.
This lab exercise on mapping collections of value types guides saving an item's images collection (strings) to a file name column, with multiple correct options.
Explore composite keys in Hibernate and JPA: implement a composite primary key with an embeddable class and embedded-id, and map a composite foreign key in a one-to-many relationship.
Explore two ways to define a composite primary key for an entity using another class’s name and age, without modifying that class, and learn about their trade-offs.
Learn how to use mapsId to borrow a department primary key as part of a user's composite primary key, avoiding duplication and embedding a derived identifier in Hibernate and JPA.
Map a bookstore object model to tables using Hibernate and JPA annotations, persisting and retrieving a book by ISBN with its publisher and chapters, including composite primary key in chapter.
Learn to map a Java object to a Json data type column using Hibernate's JdbcTypeCode annotation, persisting a book as a Json value within adjacent type column for author entity.
Learn how the Java Persistence API defines a standard for persisting data between Java objects and relational databases, as a specification, not a framework, with Hibernate as its implementation.
Explore how Hibernate works as a JPA provider and code against the JPA API with an EntityManager instead of the native Session. Learn persistence.xml and the 5.2 change extending EntityManager.
Explore the four object states in JPA: transient, persistent, detached, and removed, and learn how persist, merge, detach, and remove transitions are managed by the entity manager and persistence context.
Explore how persist, detach, and merge behave with entities in a transaction, and analyze bidirectional one-to-many relationships to predict database state after committed operations.
This lecture explains how caching works in JPA, focusing on first level caching inside an entity manager, how it speeds reads, and why second level caching would extend caching.
Explore how persistence context acts as the first level cache, enabling automatic dirty checking, flush, and repeatable reads, with details on application vs container managed entity managers.
Explore SQL joins with inner join and left outer join, using tables A and B to show matching names and explain their equivalence to join and left join.
Explore lazy fetching in Hibernate and JPA, demonstrating how proxies load collections only when needed, and why to avoid eager fetching for performance.
Investigate lazy fetching with getReference proxies and uninitialized entities that initialize on access. Explore state transitions from transient to persistent via persist, remove, and merge.
Explore how the order by annotation in JPA orders a bidirectional one-to-many collection at retrieval time, applying descending name ordering and multiple columns for lists and sets, not for persistence.
Learn how to lazily load basic data attributes by bytecode enhancement, using the basic annotation with lazy fetching and the Hibernate enhancement plugin to enable lazy initialization.
Override equals and hashCode to treat two students with the same enrollment ID as equal, ensuring correct set behavior and consistent hash codes using enrollment ID.
Explore how the equals method behaves when loading the same student with two different entity managers and comparing them, reinforcing core Hibernate and JPA concepts.
Explore how the Java Persistence Query Language (jpql) queries entities rather than tables, translating to sql at runtime, with aliases, parameters, joins, and fetch strategies in Hibernate.
This lab exercise explains flushing in Hibernate via dirty checking, the persistence context synchronization, and flush modes, including flush on commit, explicit flush, and auto versus commit behavior.
Explore the JPA criteria API for building type-safe programmatic queries, using metamodels, selecting entities or specific fields, applying where clauses, joins, fetch strategies, and named or native queries.
Generate static metamodels for your JPA entities using the Hibernate jpamodelgen jar in a Maven project; edit and recompile to refresh generated-sources, enabling type-safe criteria queries at compile time.
Master pre insert id generation with sequence strategy in Hibernate. Learn how sequences and the Hibernate sequence table assign primary keys before insert, and compare with identity and table strategies.
Learn how Hibernate 6 changes the sequence id generation by using separate sequences per entity, and how to retain the old single-sequence behavior by setting hibernate.database_structure.naming_strategy to single.
Explore inheritance mapping in Java persistence with Hibernate, compare single table, joined, and table per class strategies, and demonstrate polymorphic queries on an animal hierarchy.
this lab exercise covers inheritance mapping with a mapped superclass and subclass tables, and asks which strategy inserts base fields into animal and subclass fields into dog and cat.
Explore persisting an embeddable inheritance in Hibernate 6.6 to a single entity table with a discriminator, using an embeddable animal base with fish and dog subclasses embedded in an owner.
demonstrate how the concrete proxy annotation in Hibernate 6.6 fixes class cast exceptions when accessing subclass attributes in a single-table inheritance, by allowing accurate type resolution for lazy-loaded entities.
Learn how entity lifecycle callbacks in JPA and Hibernate trigger on events, using post load, pre persist, post persist, pre update, and related annotations to automate state changes.
Move lifecycle callbacks from an entity to an external listener using the entity listeners annotation to handle pre persist and pre update for the message entity.
If you’re a Java programmer who wants to learn the essentials and some of the advanced topics of Java Persistence with Hibernate, then you’re the one this course is designed for.
We'll be working with Hibernate 4 (with updates for Hibernate 5 & 6), and using Hibernate as a JPA Provider for the most part of this course.
You'll be learning the essentials and some of the advanced JPA features for Object/Relational Mapping, Querying, Caching, Fetching Strategies, Performance Optimizations and Concurrency.
We’ll also talk about Best Practices and how to resolve some of the common performance bottlenecks.
The course includes many Lab-Exercises in which we have tasks, Q&A and quizzes for students to revise the concepts learnt in the lectures. We also have expanded discussions on some of those lab-exercises.
We also discuss the SQL at runtime and the performance implications of it.
The Maven source-code provided with the course currently uses the Hibernate version 6.
We try to keep updating the course by adding more and new relevant topics as well. For example, the most recent topic added to the course was Embeddable Inheritance, which was introduced in Hibernate version 6.6.
We've used MySQL in the course as the RDBMS.