
Begin this course with a goal to master hibernate GPA and its related features, troubleshoot GPA-related issues, and use Q&A, learning reminders, and practice to build confidence for production projects.
Explore the course git repository in the resources to access all source code, browse commits, and study learning materials, notes, and a 110-page pdf, with clear usage policies and downloads.
Compare IntelliJ Idea community and ultimate editions, learn to create spring boot projects within the IDE, and discover six months of free ultimate access with the embark X coupon.
Explore how ORM maps classes to tables, attributes to columns, and objects to rows, enabling automatic persistence and reducing SQL coding across databases.
Discover how Hibernate sits between Java code and the database to generate SQL and persist entities, guided by JPA and used by Spring Data JPA.
Explore the H2 database, a fast in-memory, lightweight option ideal for rapid development and prototyping in Spring Boot; not recommended for production, with a browser console, JDBC support, and auto-configuration.
Explore the core of hibernate architecture: session factory, session, and transaction, and how they read configuration, map entities to tables, manage short-lived connections, and ensure commit or rollback of operations.
Learn manual Hibernate configuration in a Maven Java project by creating a hibernate.cfg.xml, adding Hibernate and H2 dependencies, configuring a session factory, and performing CRUD operations with a mapped entity.
Enable behind the scenes by printing and formatting Hibernate-generated SQL to the console, showing create table and insert queries and helping you debug database interactions.
Explore Jakarta Persistence API, a standard for mapping Java objects to relational data with JPA annotations. Learn Hibernate as the implementation reading JPA rules to generate SQL and persist data.
Transition your project from hibernate to jakarta persistence api by configuring persistence.xml, adding the jakarta persistence dependency, and using an entity manager to persist data with hibernate beneath the hood.
Review how we used Hibernate as an ORM to persist data, and how JPA provides a vendor-neutral specification with EntityManager, allowing code to decouple from underlying engines.
Transition from manual Hibernate and JPA to Spring Boot by configuring dependencies, using application properties, and leveraging auto configuration to manage entity managers and data sources.
Discover how Spring Boot Starter Data JPA simplifies JPA repositories, auto-configures the entity manager, and integrates Hibernate with an H2 database, while guiding transaction management through Spring annotations.
Set up a Spring Boot project with spring initializer, choose maven, add web, data jpa, and h2 dependencies, and import via pom.xml in IntelliJ to run the app.
Configure an h2 in-memory database with spring boot, leveraging auto configuration to create the database and h2 console, and access it via jdbc:h2:mem:test URL.
Connect to the database and define a patient entity with id, name, and age, using a Long id for nullability, annotated with @Entity, while JPA creates the table.
Learn how primary keys are generated in Spring Boot with JPA, and compare strategies like auto, identity, sequence, and table.
Explore how to persist data with JPA using entity manager and, more efficiently, Spring Data JPA repositories like CrudRepository and JpaRepository, for simplified CRUD operations.
Learn how Spring Data JPA repositories simplify persistence by saving a patient with repository.save, while Spring automatically handles transactions without manual entity manager management.
Explore how to fetch and display patients using a JPA repository, including find all, find by id, sorting, and pagination, while understanding the need for a default constructor and getters.
Update patient records by fetching the patient by id, using setters to modify fields, and saving with the repository; delete by id or by entity when needed.
Zoom out to understand the entity manager, the core JPA interface, and how it handles find, persist, merge, and remove within a persistence context and transactions.
Understand how the entity manager is the core JPA interface handling create, read, update, and delete operations, offering more control than repositories for complex queries and legacy code.
Describe how the persistence context inside the entity manager tracks entities and changes and governs lifecycle states (new, managed, detached, removed) via persist, find, merge, and remove during transactions.
Persist entities with the entity manager to save them in a transaction and mark them as managed, then compare persist with Spring Data JPA’s save for new versus existing entities.
Demonstrate how to resolve entity exist exception when persisting a duplicate id by adding a constructor and using entitymanager.persist with a patient example.
Detach a managed entity with the entity manager to stop tracking changes, then use merge to save later, since persist cannot save an already persisted object.
Discover how the entity manager's find method retrieves entities by primary key, using the persistence context to avoid extra queries and illustrating detaching effects.
Learn how getReference returns a proxy and defers data loading until access, unlike find. Use in lazy loading and foreign key scenarios, with entity not found handling.
Explore how the merge method updates detached entities, attaches them to the persistence context, and returns a managed copy within a transaction.
Delete entities with the entity manager's remove method. Ensure the entity is managed; use merge for detached copies, and remember removal is queued until transaction commit.
Flush synchronizes the current state of managed entities with the database before commit, while clear detaches all entities to reset the persistence context.
Learn how refresh in the entity manager reloads an entity from the database, discards local changes, and resyncs data during long transactions.
Reorganize the project by creating demo, repository, and model packages, move the patient entity and demonstration files into their respective packages, and discuss future refactoring for scalable code organization.
Explore the one-to-one relationship between patient and medical record, linking each record to a single patient via a primary key and patient_id foreign key, then translate it into code.
Explore implementing a one-to-one relationship in spring boot data jpa and hibernate by mapping a patient to a medical record using join column and foreign keys.
Learn how bidirectional one-to-one mappings work in Spring Boot Data JPA & Hibernate, using a patient and medical record example to show mapped by, owning side, and data traversal.
Explore the one to many relationship with a doctor and patient example, where one doctor sees many patients and each patient links to one doctor via the foreign key.
Implement a many-to-one relationship between patient and doctor by creating a doctor entity, configuring join column doctor id, and saving doctor before assigning it to patients.
Learn to implement bidirectional one-to-many and many-to-one mappings in Spring Boot Data JPA and Hibernate, enabling navigation from doctor to patients and back via mapped by and getters and setters.
Learn how cascading in Spring Boot Data JPA and Hibernate lets you save related entities automatically when persisting a patient, by configuring cascade types and owning vs non-owning sides.
Learn cascade persist in spring boot data jpa by saving doctor and patient in a single transaction, using persist to avoid detached entity errors and understand the persistence context.
Explore cascade remove in JPA by configuring doctor to cascade deletes to associated patients, avoiding integrity constraint errors when deleting linked entities.
Learn how cascade type merge propagates updates from a doctor to its patients in a one-to-many relationship, merging existing patient changes when saving the doctor.
Explore cascade type all in Spring Boot Data JPA and Hibernate, applying persist, merge, remove, refresh, and detach to a parent-child relationship, illustrated by doctor and patients and order items.
Explore the many to many relationship between medicine and prescription, and learn how a join table links them in a relational database, with examples like paracetamol and amoxicillin.
Set up a many-to-many relationship between prescriptions and medicines with a join table, define join columns, inverse join columns, and mapped by, and explain owning side using JPA and Hibernate.
Explore fetch types in Spring Boot Data JPA, including lazy loading and eager loading, and learn how default behaviors for one-to-many, many-to-one, many-to-many, and one-to-one affect performance and data loading.
Explore fetch types in spring data JPA, showing eager loading for patient with doctor and medical record, and lazy loading for one-to-many and many-to-many relations.
Explore overriding default fetch types in JPA, comparing lazy and eager in many-to-many and many-to-one relationships, with examples from prescription and medicine, and importance of default constructor and performance.
Master building and configuring relationships in a university course management system using Spring Boot Data JPA and Hibernate, including 1-to-1 student profile, 1-to-many enrollments, and instructor-course mappings.
Learn how embeddable and embedded work in JPA by embedding a reusable address class into patient and doctor, with fields flattened into the owning tables.
Implement address as an embeddable class and reuse it with embedded fields—street, city, state, and zip code—in patient and doctor, enabling shared address data without a separate table.
Define composite keys as two or more columns that uniquely identify a record, such as patient id and doctor id in prescriptions, avoiding random surrogate ids.
implement a composite key for the prescription entity using @IdClass with doctor ID and patient ID. define prescription ID, implement serializable, and override equals and hashCode for entity identity.
Refine and verify composite keys in a Spring Boot data JPA app by aligning key fields, renaming doctor id and patient id, and validating prescription's joined relationships.
Establish bidirectional navigation between doctor, patient, and prescriptions by adding one-to-many mappings, using mapped by fields, lazy fetch, and cascade options to navigate without schema changes.
Populate and relate data in a Spring Boot app by creating a composite key for prescriptions and seeding doctors, patients, medical records, and medicines with a command line runner.
Explore defining composite keys in Spring Data JPA using @EmbeddedId, embeddable, and @MapsId, linking prescription, doctor, and patient IDs while comparing embedded and id-based approaches.
Explore how the @Table annotation maps an entity to a database table, customize the table name with name, and configure schema, catalog, unique constraints, and indexes for efficient queries.
Choose a generation type to auto-generate primary keys in a JPA entity, using identity, sequence, or table strategies, with auto as default and sequence generators for custom databases.
The column annotation provides fine-grained control over mapping fields to database columns, including name, unique, nullable, insertable, updatable, length, precision, scale, and table; demonstrates renaming a field to patient_name.
Learn how to store large objects in the database with the @Lob annotation in JPA, using clob for text and blob for binary data stored as byte arrays.
Derive the age group from age and mark it as transient with @Transient so it stays in memory and does not persist in the database.
Master how the @Enumerated annotation maps Java enums to database columns, replacing free text with fixed values like gender. Enforce valid values, gain type safety, and future-proof your schema.
Learn how to auto-populate creation and update timestamps in JPA with Java 8 time API using Hibernate annotations, enabling automatic timestamp management for entities.
Explore how the @Version annotation enables optimistic locking in JPA to prevent lost updates, with an auto-incremented version field and optimistic lock exceptions when conflicts occur.
Explore how inheritance in object oriented programming creates a person base class for doctor and patient, enabling code reuse. See how JPA maps this inheritance to database tables.
Identify the duplication between patient and doctor entities and learn how a base class with common fields enables inheritance, reducing code repetition and future-proofing your Spring Boot JPA models.
Explore how Spring Boot data JPA maps Java inheritance to relational tables, comparing single table, table per class, and join table strategies, including performance, normalization, and null-value trade-offs.
Implement joined table inheritance in Spring Boot Data JPA by creating a common Person base class and extending it with Doctor and Patient, using the join strategy and repositories.
Apply the single table inheritance strategy by using a discriminator column (dtype, renamed to person type) in the person table to store doctor and patient data.
Implement the table per class inheritance in Spring Boot Data JPA, converting identity to auto, removing the discriminator, and marking person abstract to avoid a separate person table.
Explore basic jpql queries using an entity manager to fetch patients with typed queries, map results to patient entities, and apply filtering with where clauses and named parameters.
separate the data initializer from queries to illustrate typed versus untyped queries, using entity manager create query to return typed results or untyped lists via get result list.
Explore named and positional query parameters in Spring Boot Data JPA, using EntityManager and TypedQuery to filter patients by name and gender, and compare readability and order sensitivity.
Translate learning into repository logic by transforming hard-coded JPQL queries into a Spring Data JPA repository, using derived and custom JPQL methods with the @Query annotation and parameter binding.
Learn how JPA derives queries from repository method names using conventions like find by name and find by name and gender, and when to write gql for complex cases.
Explore jpql conditional expressions with the entity manager, using comparison operators, like, in, not in, between, and is null or is not null to fetch data.
Sort results by age or name using order by, explore ascending and descending orders, and combine multiple sort criteria with gender filtering to shape query results.
Explore JPQL joins, including inner join, left join, and join fetch, to fetch patients with doctors and avoid lazy loading errors by eagerly retrieving related data.
Explore aggregation and grouping with count, sum, average, max, and min to derive patient counts by doctor specialization and average age by gender in Spring Boot Data JPA.
Explore bulk updates and bulk deletes in Spring Boot Data JPA, using modifying and transactional annotations to safely modify data and manage batch operations.
Master constructor expressions to fetch only required fields by mapping query results to a DTO, such as patient summary, reducing data transfer and improving performance in Spring Boot Data JPA.
Define and reuse named queries embedded in entities to fetch patients by name prefixes, using entity manager or repository mappings for centralized, reusable query logic.
Learn to extract order insights with JPQL in a Spring Boot Data JPA project, including high value orders, top selling products, revenue by customer, and canceling stale pending orders.
Define a transaction as a sequence of operations that completes as a single unit, with all or none. Apply ACID—atomicity, consistency, isolation, durability—to guide safe multi-user banking and e-commerce.
Discover how without transactions, multi-step operations risk partial updates and an inconsistent state, and how isolation, atomicity, and durability prevent dirty reads, lost updates, and phantom reads.
Simulate a failure to demonstrate data inconsistency when transactions are not used. Save a patient and a medical record, then throw an error to show the broken relationship.
Wrap a method in a transaction with the transactional annotation to ensure commit or rollback, and learn default rollback on unchecked exceptions plus configuring rollback on checked exceptions.
Experience how JPA translates Java objects to database tables and enables seamless switching between databases like H2, MySQL, and PostgreSQL with minimal Spring Boot configuration.
Install MySQL on Windows using the offline installer, install MySQL server, shell, and Workbench, configure the root password and startup service, and connect to localhost:3306.
Install MySQL on mac by downloading MySQL community server, selecting mac os version (arm or x86), and running the dmg installer. Configure a root password and connect with MySQL Workbench.
Navigate the MySQL Workbench interface, explore the administration tool, schemas, tables, and the query panel, and learn to run statements with the cursor or full script while adjusting font settings.
Configure your Spring Boot app to connect to a MySQL database by creating a schema, adding the MySQL dependency, and setting data source URL, credentials, and dialect in application properties.
Install PostgreSQL on Windows by downloading the official installer, choosing 64-bit if appropriate, and completing the setup with pgadmin, stack builder, and a memorable password.
Connect to Postgres with pgadmin, join the local instance, and view the public schema. Learn to add a server, enter host details, and create a new database.
Configure your Spring Boot app to PostgreSQL by adding the PostgreSQL driver and creating a JPA demo database; set JDBC URL, username, password, dialect, and DDL auto to update.
Master Hibernate and JPA with Spring Boot – A Complete Hands-On Course by EmbarkX
UPDATED TO SPRING FRAMEWORK 7 AND SPRING BOOT 4
EmbarkX presents a definitive journey into Hibernate, JPA, and Spring Boot—designed for Java developers aiming to build high-performance, maintainable applications. In this comprehensive program, you’ll start with an Introduction to Hibernate and How It Works, covering the core concepts of object-relational mapping (ORM), session management, and transactions. From there, you’ll dive into Understanding Our Project, where you’ll set up a Spring Boot application that serves as the backbone for all hands-on exercises.
Next, you’ll explore Introduction to JPA and Foundations of Persistence in Java, learning about the JPA specification, EntityManager, persistence contexts, and how JPA standardizes data access. By Taking a Step Back – Exploring Under the Hood, you’ll gain clarity on the differences between Hibernate’s native APIs and the JPA layer, ensuring you understand both performance optimizations and portability across JPA implementations.
Moving forward, you’ll learn Mapping Real-World Data Models with Relationships, tackling one-to-one, one-to-many, many-to-one, and many-to-many associations. Dive into JPA Annotations You Should Be Aware Of, mastering annotations like @Entity, @Table, @Id, @GeneratedValue, @Column, @Embedded, and advanced mapping techniques. You’ll also cover Inheritance with JPA, implementing strategies such as SINGLE_TABLE, JOINED, and TABLE_PER_CLASS to model class hierarchies effectively.
The section on Querying and the Criteria API introduces JPQL, named queries, and dynamic queries. You’ll see how to fetch data efficiently, and build type-safe queries without writing raw SQL. Finally, Different Databases with Spring Boot demonstrates configuring various relational databases—H2, MySQL, PostgreSQL—showing you how to switch data sources.
By the end of this course, you will:
Confidently use Hibernate and Spring Data JPA annotations.
Build complex entity relationships and inheritance mappings.
Write advanced JPQL and Criteria API queries.
Integrate your Spring Boot application with multiple database engines.
Join EmbarkX to unlock the power of Hibernate, JPA, and Spring Boot, and elevate your Java expertise to build real-world, enterprise-grade applications!