
Master hibernate and jpa with spring boot by migrating from jdbc to jpa, exploring entities, relationships, and querying with jpql, native queries, criteria API, plus Ehcache caching and transaction management.
Set a daily learning goal and commit to at least half an hour to master Spring and Spring Boot by building restful web services and microservices with Maven and Git.
Explore seven independent sections that cover introduction to JPA, Spring Boot basics, JDBC to JPA migration, JUnit, a deep dive into Hibernate and JPA, queries, transactions, and caching.
Explore the GitHub repository for JPA with Hibernate, with installation guide, hands-on sections, step-by-step code, and extensive intermediate backups you can download and import as Maven projects.
Install Java and Eclipse to begin, with IntelliJ IDEA or Visual Studio Code options; follow in28minutes repo for Java setup videos and troubleshooting, stay updated with Java and Spring Boot.
Discover how JPA maps Java objects to database tables through entities and relationships, and explore JPQL, criteria queries, and native SQL for data access.
Explore why Spring Boot enables building web applications and REST APIs, compare it with Spring MVC, and learn auto configuration, developer tools, and actuator through a hands-on project.
Compare the pre-spring boot era, where teams manually managed dependencies and XML configurations, with Spring Boot that streamlines setup, logging, error handling, and monitoring.
Set up a new Spring Boot project with Spring Initializr, configure Maven and Java versions, add Spring Boot web dependencies, and run on Tomcat (port 8080).
Build a simple rest api with Spring Boot and expose the /courses endpoint to return a list of courses with id, name, and author.
Understand the goal of Spring Boot: quickly build production-ready applications using starter projects, auto-configuration, and dev tools, with environment-specific configurations and actuator for monitoring.
Spring Boot starter projects provide convenient dependency descriptors that bundle web, test, and data features (for example, spring-boot-starter-web-mvc and spring-boot-starter-data-jpa) for quick rest api development, with configuration next steps.
Explore how Spring Boot auto-configuration simplifies web applications by auto-configuring dispatcher servlet, embedded Tomcat, and JSON conversion via Jackson based on class path and existing settings.
Boost your development productivity with Spring Boot DevTools, enabling automatic restarts on code and property changes, and clarifying that pom.xml changes require manual restart.
Use spring profiles to create environment-specific configurations, with separate application-dev.properties and application-prod.properties merged into default properties, and set spring.profiles.active to switch dev and prod environments and logging levels.
Configure a currency service with configuration properties and a currency service prefix to map url, username, and key. Leverage profiles to switch configurations via application properties.
Learn how Spring Boot embedded servers simplify production deployment by running a single jar that includes Tomcat by default, with options for Jetty or Undertow.
Learn how spring boot actuator enables production monitoring by exposing health, metrics, beans, and mappings endpoints, and how to enable and configure them via application.properties for your app.
Explore Spring framework's dependency injection and component scanning, Spring MVC for web and REST APIs, and how Spring Boot wraps Spring MVC with starter projects and auto configuration.
Review a high-level overview of Springboard concepts, including startup projects, auto configuration, and actuator dev tools, and explore the production-ready advantages as you build more features.
Discover strategies to improve long-term memory through active learning and regular review. Learn to take notes when you learn and review them every few days or weeks to reinforce retention.
Explore the journey from spring jdbc to JPA, migrating a simple spring jdbc example to JPA, and learn JPA basics, entities, repositories, and CRUD operations.
Set up a Spring Boot project with JDBC, JPA, H2, and Web dependencies using start.spring.io, import as a Maven project, and run a basic app on Tomcat 8080.
Connect to an embedded H2 in-memory database and launch the H2 console via Spring Boot auto configuration; explore tables, create data, and learn how to switch databases by adjusting properties.
Create a person table in h2 via data.sql, leveraging Spring Boot auto configuration, defining id (primary key, not null), name, location, and birth_date (timestamp), then verify in the h2 console.
Populate the person table by executing an insert query and seed data with data.sql to insert 10001 Ranga Hyderabad, 10002 James New York, and 10003 Peter Amsterdam for JDBC practice.
Implement a Spring JDBC find all method in a Person JDBC DAO using JDBC template to query the person table and map results to a Person bean via BeanPropertyRowMapper.
Execute the findAll method at startup with a Spring Boot command line runner, autowire the person JDBC DAO, log results, and format output with a toString for clear, line-by-line display.
Compare jdbc with spring jdbc and see how spring jdbc simplifies code and prevents connection leaks using the jdbc template.
Explore how Spring Boot auto configuration wires JdbcTemplate and data source by detecting classpath items like H2 and web servlet, and view the auto configuration report in debug mode.
Implement a findById query using Spring JDBC's queryForObject to fetch a single person by id with a parameter array and a where id = ? clause.
Implement a delete by id operation using JdbcTemplate's update method, returning the number of rows affected and confirming deletion in the H2 database.
Implement insert and update operations in Spring JDBC, using a person object, parameterized queries, and birth date timestamp, then run and verify changes in the database.
Create a custom Spring JDBC RowMapper by implementing RowMapper for the Person class, mapping id, name, location, and birth date from a timestamp column, enabling reusable mapping across DAOs.
Map entities to tables with JPA, define relationships such as a person to addresses, and understand Hibernate as the popular JPA implementation enabling ORM.
Define a person entity using JPA and Hibernate, mapping the class to the person table, configuring id generation with @Id and @GeneratedValue, and providing a no-arg constructor for Hibernate.
In step 15, define a repository for the person entity, enable transactions, connect via an entity manager, and implement a findById method using JPA to fetch data from in-memory database.
Implement insert and update operations using entitymanager.merge in a JPA repository, letting Hibernate assign IDs via a sequence, and observe automatic insert and subsequent updates in the demo app.
Implement delete by id by first finding the person by id, then calling entityManager.remove to delete, and verify the deletion in the H2 console.
Implement a find all using a JPQL named query with the entity manager, defining the named query on the Person entity and returning a list of Person with getResultList.
Explore unit testing with JUnit in five steps and learn to write tests for JPA with Hibernate using the provided code examples and GitHub resources.
Learn why unit testing matters with JUnit, compare unit, system, and integration testing, and see how continuous integration helps catch bugs early through tests.
Create a Java project in Eclipse, implement a simple My Math sum method, and write a JUnit 5 test with assertions to confirm a green bar.
Expand and refine unit tests by duplicating tests for new inputs, validating that an empty array yields zero, and improving test naming and refactoring for clarity in continuous integration.
Explore the breadth of JUnit assertion methods, including assertEquals for booleans, numbers, and arrays, using messages for failures and understanding test outcomes.
Master key JUnit annotations like before each, after each, before all, and after all, and learn setup, cleanup, and test execution order concepts, including that test order may vary.
Explore entities and annotations, relationships, and inheritance in depth, and master the entity manager, persistence context, and diverse querying options with JPA, native queries, and Criteria API.
Create a Maven Java project with Spring Boot, include Web, JPA, and H2 dependencies, import the zip into Eclipse, and run a Spring Boot context to verify the application starts.
Create a simple JPA entity named course with a primary key id generated value, a name field, getters, a protected no-arg constructor, and prepare for repository access.
Learn to manage course data with a JPA repository and an entity manager, implement find by id, and run a Spring Boot app to fetch the course.
Enable the H2 console and Hibernate statistics, turn on show sql and parameter logging, and format queries to observe schema creation and data population with Spring Boot.
Create a unit test for the course repository findById method, verify the returned course name, and understand running a spring boot test with an in-memory H2 database.
Learn to implement a delete by id method for a course using an entity manager, with find by id and transactional safeguards to ensure safe removal.
Write a unit test for the delete by id method, deleting the row with id 10002 and verifying it no longer exists by asserting null on find by id. Use a dirty context annotation to reset data after the test so other tests remain unaffected.
Implement a save method in Spring Boot with Hibernate JPA that inserts when id is null and updates with merge when id is present, using entity manager persist and merge.
Learn to write unit tests for the save method in a Spring Boot JPA context, updating a course entity and validating changes via repository save and database queries.
Review the course's entity and repository, covering CRUD operations, find by id, save for insert/update, and delete by id, with unit tests and a dirty context annotation.
Explore how the entity manager tracks changes within a transaction, as it persists inserts and updates automatically when you modify a course, without explicit save calls.
Explore how the entity manager tracks changes within a transaction, using persist, merge, flush, detach, and clear to control when updates are written to the database.
Explore the entity manager refresh method, which reloads course one from the database, discarding in-memory changes after a flush, while updates to course two persist.
Review the entity manager as a gateway to the persistence context. Master how merge, persist, remove, flush, refresh, and detach manage entities during a transaction.
Master JPQL basics by writing queries against entities, using an entity manager and typed queries, with where conditions and like percent patterns.
Map a course entity to the course table using the @Table annotation, showing how to handle differing entity and table names and the impact on generated queries.
Use the @Column annotation to map a field to a column named full name, enforce non-null constraints, and control insertable and updatable behavior along with options like length and unique.
Learn how to automatically manage created and updated timestamps with Hibernate and JPA using @CreationTimestamp and @UpdateTimestamp on LocalDateTime for inserts and updates.
Learn to define and reuse queries with JPA and Hibernate annotations by using @NamedQuery for single queries and @NamedQueries for multiples, then apply in code and tests.
Master native queries in JPA with the entity manager, mapping results to entities and using positional or named parameters; apply for database specific features and mass updates.
Develop consistency by following a concrete two week learning plan, study a few hours daily, and keep the plan visible to boost memory over the long run.
Explore entities such as course, student, passport, and review, and learn how to map relationships, including many-to-many between courses and students, one-to-one between student and passport, and many-to-one for reviews.
Define student, passport, and review entities, set up sample data, adjust fields and naming conventions, and prep for relationship mappings in a Hibernate and JPA starter project.
Define a 1 to 1 relationship between student and passport using JPA. Choose which side owns the relationship (student or passport) and implement a foreign key to connect the tables.
Persist the passport first, then create and save the student to establish a one-to-one relationship where the student owns the passport, using the entity manager and a student repository.
Retrieve a student and their passport in a unit test using a one-to-one mapping, demonstrating eager fetch and the automatic join of passport details.
Explore a one-to-one mapping with lazy fetch in Hibernate, showing how to retrieve only the student while delaying passport data and managing session and transaction scope to avoid initialization exception.
Explore how transaction boundaries, the persistence context, and the entity manager coordinate multiple database operations, ensuring all succeed or none, and clarify the role of Hibernate sessions in JPA.
Learn bidirectional one-to-one mapping between student and passport in a Spring Boot JPA setup, and designate the owning side with mappedBy to enable reverse navigation.
Explore bidirectional one-to-one mappings between student and passport in Hibernate and JPA, highlighting the owning side and mapped by. Navigate from passport to student and back to validate the relationship.
Hibernate defers inserts and updates until the end of a transaction, tracking changes in the persistence context. Use flush to push changes early, and a failure triggers a rollback.
Discover when to apply @Transactional in unit tests to ensure database changes run within a transaction, especially when using the entity manager directly instead of repository methods.
Examine whether read-only methods require transactions, compare entity manager finds with relationship-driven lazy loading, and learn why @Transactional is needed for querying related data such as user and comments.
Explain why @DirtiesContext is essential in unit tests. Show how updating course data via data.sql can affect subsequent tests and how rollback restores the initial database state.
Explore many-to-one relationships by linking reviews to courses with a course_id foreign key, explaining one-to-many mappings and the early design decisions before mapping in entities.
Explain a one-to-many mapping from course to reviews and a many-to-one from review to course, using mapped by and add/remove review methods with a foreign key course_id.
retrieve a course by id 10,003, create and attach two reviews, set the course on each review, and persist them to demonstrate many-to-one relationship in spring boot in 100 steps.
Generalize the add reviews method to accept a course id and a list of reviews, replacing hardcoded data and enabling a many-to-one mapping for a specific course.
Wraps up many-to-one mapping by exploring lazy and eager fetching for course and review, showing default behavior and how transactional persistence context affects retrieval.
Explore the many-to-many relationship between courses and students, and design a join table with course_id and student_id as foreign keys to link records in both tables.
Implement a many-to-many relationship between court and student by annotating entities and adding student and course collections, revealing a join table court_students and guiding future fixes.
Learn how to fix the two-join-table problem in a many-to-many relationship by designating an owning side and using mapped by to create a single student_courses join table.
Customize the many-to-many mapping between student and course by using @JoinTable on the owning side, naming the join table student_course with student_id and course_id.
Insert data into the student_course join table and perform a three-table join to display which students belong to each course, preparing for JPA-based retrieval of relationships.
Retrieve a student and their courses using JPA many-to-many mappings, exploring lazy and eager fetch options, entity manager usage, and join queries in a Spring Boot Hibernate context.
Persist a new student and a new course, establish their many-to-many relationship in JPA using the owning side, and verify the inserts in the database.
Explore how JPA maps 1-to-1, 1-to-many, and many-to-many relationships, including owning sides, join tables, and fetch types, with practical guidance on designing and querying related entities.
Reframe failures as learning opportunities by analyzing what went wrong. Seek input from mentors or peers, keep a failure journal, and embrace hands-on learning as a path to success.
Explore inheritance hierarchies and mappings in Hibernate and JPA with Spring Boot, using employee types and strategies—single table, table per class, joined, mapped superclass—to assess insert and retrieval efficiency.
Define a JPA inheritance hierarchy by creating an abstract employee entity with id and name, extended by full-time and part-time employees with salary and hourly wage, then add a repository.
Create and use an employee repository to insert employees with entity manager persist and retrieve all employees via a query, setting up for JPA inheritance mappings.
Explore the single table inheritance strategy in JPA, mapping part-time and full-time employees to a single employee table with a discriminator column. Compare performance benefits with data integrity risks.
Explore the table per class inheritance strategy in JPA, where each concrete subclass has its own table, with common columns repeated and data retrieved by union.
Study the joined inheritance strategy, where the superclass and each subclass map to three tables joined to instantiate subclass details, with potential performance costs.
Explore mapped superclass as an inheritance option in JPA, noting that it is not an entity, requires separate tables for subclasses, and mandates individual queries for full-time and part-time employees.
Navigate JPA inheritance mappings by weighing single table, table per class, joined, and mapped superclass approaches, balancing data integrity and performance to choose the right option.
Write jpql queries that identify courses without students by leveraging the course and student relationship, using the data in data.sql and the h2 console to verify results.
Write jpql queries to find courses with at least two students. Order results by the number of students using size of C.students, in descending order.
Learn to write jpql queries using like to find students whose passport numbers match a pattern, and explore utility string functions and basic sql concepts like between and joins.
Explore JPQL joins in Hibernate: inner joins, left joins, and cross joins between course and student, with examples showing results, including courses without students and cross products.
Hibernate is the most popular Java ORM framework. Almost every Real World Project today uses JPA and Hibernate in combination with Spring Boot and Spring Data JPA.
Do you want to Learn JPA & Hibernate and use them in combination with Spring Boot and Spring Data JPA? Do you want to Learn about Entities, Relationships, Entity Manager, JPQL, Native Queries, Inheritance Hierarchies, Criteria API, Transaction Management, Caching and Performance Tuning with JPA & Hibernate in combination with Spring Data JPA and Spring Data REST?
WHAT OUR LEARNERS ARE SAYING:
5 STARS - I really loved this course. The instructor explains features of JPA and Hibernate clearly and also very deeply. Especially I liked explanation of the transaction management what I didn't seen in other courses.By the way this course helped me to develop the persistence layer of a commercial application for my customer.
5 STARS - Absolute brilliant course, I was struggling using books but this course helped me understand using code to demonstrate how Hibernate and JPA work. Each video builds on the next and is at a pace that does not overwhelm you. I thoroughly recommend this course if you need to improve your Hibernate and JPA knowledge.
5 STARS - It is really state of the art and how spring boot and hibernate are used nowadays! This course was very helpful in my new job, since in the project we use spring boot and hibernate. Thank you!
5 STARS - This course exceeded my expectations, I thought I knew about hibernate but I discovered I didn't, I really recommend this course.
5 STARS - Thanks Ranga for the wonderful course on Hibernate and JPA with Spring Boot! It's a long course and well worth it. Keep up the great work!
COURSE OVERVIEW
Hibernate is the most popular implementation of JPA. It was the most popular ORM framework option before JPA emerged and it provides additional features on top of JPA. We will use Hibernate as the JPA implementation in this course.
The Java Persistence API provides Java developers with an api for mapping java objects to relational data. In this course, you will learn about the Hibernate, JPA API, JPQL (Java Persistence query language), Java Persistence Criteria API and how you can perform ORM (Object Relational Mapping) with JPA and Hibernate.
During this course
You will learn the basics of JPA and Hibernate - Entities, Relationships, Inheritance Mappings and Annotations
You will understand approaches to querying data using JPA and Hibernate - JPQL, Criteria API and Native Queries
You will understand JPA and Hibernate Relationships in depth - One to One, Many to One and Many to Many
You will use a variety of Spring Boot Starters - Spring Boot Starter Web, Starter Data Jpa, Starter Test
You will learn the basic of performance tuning your JPA application with Hibernate - Solve N+1 Queries Issue.
You will learn the basics of caching - First Level Cache and Second Level Cache with EhCache
You will understand the basics of Spring Data JPA and Spring Data REST
COURSE HIGHLIGHTS
Journey from JDBC To JPA
Step01 - Setting up a project with JDBC, JPA, H2 and Web Dependencies
Step02 - Launching up H2 Console
Step03 - Creating a Database Table in H2
Step04 - Populate data into Person Table
Step05 - Implement findAll persons Spring JDBC Query Method
Step06 - Execute the findAll method using CommandLineRunner
Step07 - A Quick Review - JDBC vs Spring JDBC
Step08 - Whats in the background? Understanding Spring Boot Autoconfiguration
Step09 - Implementing findById Spring JDBC Query Method
Step10 - Implementing deleteById Spring JDBC Update Method
Step11 - Implementing insert and update Spring JDBC Update Methods
Step12 - Creating a custom Spring JDBC RowMapper
Step13 - Quick introduction to JPA
Step14 - Defining Person Entity
Step15 - Implementing findById JPA Repository Method
Step16 - Implementing insert and update JPA Repository Methods
Step17 - Implementing deleteById JPA Repository Method
Step18 - Implementing findAll using JPQL Named Query
JPA/Hibernate in Depth
Step01 - Create a JPA Project with H2 and Spring Boot
Step02 - Create JPA Entity Course
Step03 - Create findById using JPA Entity Manager
Step04 - Configuring application.properties to enable H2 console and additional logging
Step05 - Writing Unit Test for findById method
Step06 - Writing a deleteByID method to delete an Entity
Step07 - Writing Unit Test for deleteById method
Step08 - Writing a save method to update and insert an Entity
Step09 - Writing Unit Test for save method
Step10 - Quick Review and Debugging Tips
Step11 - Playing with Entity Manager
Step12 - Entity Manager Methods - clear and detach
Step13 - Entity Manager Methods - refresh
Step14 - A Quick Review of Entity Manager
Step15 - JPQL - Basics
Step16 - JPA and Hibernate Annotations - @Table
Step17 - JPA and Hibernate Annotations - @Column
Step18 - JPA and Hibernate Annotations - @UpdateTimestamp and @CreationTimestamp
Step19 - JPA and Hibernate Annotations - @NamedQuery and @NamedQueries
Step20 - Native Queries - Basics
Step21 - Entities and Relationships - An overview
Step22 - Defining Entities - Student, Passport and Review
Step23 - Introduction to One to One Relationship
Step24 - OneToOne Mapping - Insert Student with Passport
Step25 - OneToOne Mapping - Retrieving Student with Passport and Eager Fetch
Step26 - OneToOne Mapping - Lazy Fetch
Step27 - Session vs Transaction
Step28 - OneToOne Mapping - Bidirectional Relationship - Part 1
Step29 - OneToOne Mapping - Bidirectional Relationship - Part 2
Step30 - ManyToOne Mapping - Designing the database
Step31 - ManyToOne Mapping - Retrieving and inserting Reviews for Course
Step32 - ManyToOne Mapping - Generalizing Insert Reviews
Step33 - ManyToOne Mapping - Wrapping up
Step34 - ManyToMany Mapping - Table Design
Step35 - ManyToMany Mapping - Adding Annotations on Entities
Step36 - ManyToMany Mapping - Fixing two join tables problem
Step37 - ManyToMany Mapping - Customizing the Join Table
Step38 - ManyToMany Mapping - Insert Data and Write Join Query
Step39 - ManyToMany Mapping - Retrieve Data using JPA Relationships
Step40 - ManyToMany Mapping - Insert Student and Course
Step41 - Relationships between JPA Entities - A summary
Step42 - Introduction to Inheritance Hierarchies and Mappings
Step43 - JPA Inheritance Hierarchies and Mappings - Setting up entities
Step44 - JPA Inheritance Hierarchies and Mappings - Setting up a Repository
Step45 - JPA Inheritance Hierarchies and Mappings - Single Table
Step46 - JPA Inheritance Hierarchies and Mappings - Table Per Class
Step47 - JPA Inheritance Hierarchies and Mappings - Joined
Step48 - JPA Inheritance Hierarchies and Mappings - Mapped Super Class
Step49 - JPA Inheritance Hierarchies and Mappings - How to Choose?
Step50 - JPQL - Courses without Students
Step51 - JPQL - Courses with atleast 2 Students and order by
Step52 - JPQL - Courses like 100 Steps
Step53 - JPQL - Using Joins
Step54 - Criteria Query - Retrieving all courses
Step55 - Criteria Query - Courses like 100 Steps
Step56 - Criteria Query - Courses without Students
Step57 - Criteria Query - Using Joins
Step58 - Introduction to Transaction Management
Step59 - Transaction Management - ACID Properties
Step60 - Understanding Dirty, Phanthom and Non Repeatable Reads
Step61 - Understand 4 Isolation Levels
Step62 - Choosing between Isolation Levels
Step63 - Implementing Transaction Management - 3 Things to Decide
Step64 - Introduction to Spring Data JPA
Step65 - Testing the Spring Data JPA Repository with findById.
Step66 - Spring Data JPA Repository - CRUD Methosd
Step67 - Sorting using Spring Data JPA Repository
Step68 - Pagination using Spring Data JPA Repository
Step69 - Custom Queries using Spring Data JPA Repository
Step70 - Spring Data REST
Step71 - Introduction to Caching
Step72 - Hibernate and JPA Caching - First Level Cache
Step73 - Hibernate and JPA Caching - Basics of Second Level Cache with EhCache
Step74 - Hibernate and JPA Caching - Second Level Cache Part 2
Step75 - Hibernate Tips - Hibernate Soft Deletes - @SQLDelete and @Where
Step76 - Hibernate Soft Deletes - Part 2
Step77 - JPA Entity Life Cycle Methods
Step78 - Using Embedded and Embeddable with JPA
Step79 - Using Enums with JPA
Step80 - JPA Tip - Be cautious with toString method implementations
Step81 - JPA Tip - When do you use JPA?
Step82 - Performance Tuning - Measure before Tuning
Step83 - Performance Tuning - Indexes
Step84 - Performance Tuning - Use Appropriate Caching
Step85 - Performance Tuning - Eager vs Lazy Fetch
Step86 - Performance Tuning - Avoid N+1 Problems
Hibernate Tips & Tricks
When does Hibernate send updates to the database?
When do we need @Transactional in an Unit Test?
Do read only methods need a transaction?
Why do we use @DirtiesContext in an Unit Test?
How to connect to a different database with Spring Boot?
How do you approach designing great applications with JPA?
Good Practices for developing JPA Applications
Start Learning Now. Hit the Enroll Button!