
Explore Spring Data JPA with Hibernate from beginner to guru, starting with course housekeeping, environment setup, and GitHub workflows before diving into the core content.
Learn about the recommended GitHub workflow for the course.
Dive into spring data jpa with an example by creating an entity and a repository, persisting data in an in-memory h2 database auto-configured by spring boot, and later introduce mysql.
Create a book domain object, turn it into a jpa entity with @Entity and @Id/@GeneratedValue(auto), and ensure a no-arg constructor for Hibernate with title, ISBN, and publisher.
Learn how Hibernate uses id-based equality for persistent entities, implement equals and hashCode, and handle null IDs before database assignment to ensure correct persistence behavior.
Define a repository by extending JpaRepository for a domain type Book with a long ID. Spring Data JPA then provides an implementation and supports CRUD operations.
Initialize sample data with Spring by using a data initializer to save two books via a repository into an H2 in-memory database, powered by Spring Data JPA and Hibernate.
Enable spring data jpa show sql to log the actual sql statements. Format the output and enable trace to see bind parameters for troubleshooting and understanding sql injection prevention.
Explore how a database organizes related data, defines data types, and supports data manipulation, retrieval, and administration through a DBMS, including flat file, relational, hierarchical, NoSQL, and cloud databases.
Explore relational database principles, SQL data definition and manipulation, primary keys (surrogate vs natural), foreign keys, and one-to-many relations, with ACID transactions and locking strategies (pessimistic and optimistic).
Explore what a relational database management system (RDBMS) is and how it uses ANSI SQL, DDL, and DML to define, manipulate, and retrieve data with ACID, security, and schema.
Trace MySQL's history from relational model origins to Oracle ownership, MariaDB fork, and open-source status, and note ANSI SQL, portability, and features like stored procedures and triggers.
Create a minimal-access service account and a dedicated schema for Spring Boot, using two MySQL 8 users: bookadmin with ddl privileges and bookuser with dml access in bookdb.
Demonstrates how database transactions are managed in tests, including implicit transactions, commit and rollback, and how test method order and transactional context shape data state.
Configure Hibernate to connect Spring Boot tests to MySQL and balance in-memory and real database testing with initialized data for Spring Data JPA.
Explore Hibernate DDL and the Hbm2ddl auto configuration to generate, update, or drop schema from JPA entities, and learn when to use it versus Flyway for migrations.
Write an integration test for MySQL using a local profile, override H2 with auto-configure test database none, and validate that two records load after initialization.
configure hibernate to initialize the database from a classpath schema sql file, creating the book table and sequences, with id generation aligned to new naming strategies.
Generate a changelog from an existing database using Liquibase's generateChangeLog to create a sequence of changesets and a ChangeLog file, showing how to configure Maven goals, outputChangeLogFile, author, and changeLogSchemaName.
Follow Liquibase best practices by organizing change logs with a master file referencing individual changesets. Create a resources/db/changelog structure, add a baseline file, and commit these changes to git.
Initialize data with Liquibase by using XML descriptors or SQL change types in a Spring Boot project, setting up changeSets, including files, and inserting initial values into the Hibernate sequence.
Explore Flyway for database migrations, including commands like migrate, clean, info, validate, baseline, and repair, and learn how Spring Boot integrates Flyway to manage schema changes.
Configure Spring Boot to run Flyway migrations by adding the flyway-core dependency and using the bookadmin datasource for migrations.
configure a Spring Boot dev setup to clean and rebuild the database with Flyway: enable the Flyway clean goal via a clean profile and corresponding properties, then migrate.
Explore Hibernate primary keys and mapping, comparing surrogate key options (integer, long, UUID) with legacy natural keys, while the course uses Flyway and Liquibase for migrations and introduces DAO patterns.
Change author and book tables to auto-incremented primary keys by switching from auto to identity, updating Flyway migrations and database scripts. Highlight vendor-specific migration strategies for MySQL and H2.
Implement vendor specific flyway migrations for H2 and MySQL, fix H2 identity syntax, refactor scripts into common and vendor folders, and configure Spring Boot to load both locations for tests.
Set up a uid as a primary key using a varchar(36) column and map it with Hibernate to store a string uid. Compare this to a binary storage approach.
Generate an RFC 4122 compliant UUID using a new Hibernate uuid2 generator, store it as binary(16) for space efficiency, and map it for entities like bookUuid and authorUuid.
Explore how JDBC implements the DAO pattern, compare with Hibernate, and learn when to use JDBC directly, Spring JDBC template, and Hibernate to manage primary keys and data access.
Explore the Java DAO pattern, isolating persistence operations from the application layer, and implement CRUD via a DAO interface and JDBC-based implementation with Spring Boot.
Create an author DAO with a get by id method and its spring component, then test under a local profile while addressing test context scanning with component scan and import.
Save a new author via the DAO and return the saved author with its id. Learn binding parameters, performing the insert, and retrieving the last insert id with MySQL.
Implement and test updating an existing author in a transactional integration test, using a custom DAO update, update SQL, and a get-by-id check to verify changes.
Implement delete author by id using JDBC with a proper where clause, and understand how Spring transactional context affects test rollback versus plain JDBC.
Explore the DAO pattern with JDBC and learn why the Spring JDBC Template simplifies database access, setting the stage for later Hibernate integration.
Explore Spring JDBC Template as an abstraction over JDBC, map queries to objects, and implement a DAO layer for cleaner data access.
Implement a Spring RowMapper to map a result set row to an author with id, first name, and last name, and use a new mapper with JDBC template.
Demonstrates modeling an author with a list of books using a single left outer join and JDBC template, mapping multiple rows to a full author object.
Hibernate is the default JPA implementation used by Spring Data JPA.
NOTE: Java 17 and Spring Boot 3 are required for this course.
JPA stands for Java Persistence API. This is a common Java API used to work with Relational Databases.
Spring Data JPA is an abstraction built on top of the JPA API specification.
Being an abstraction, Spring Data JPA makes working with database entities very efficient.
Spring Data JPA eliminates a lot of the boilerplate / cerimonial code, and allows developers to focus on developing business logic.
The downside of the efficient abstraction is that accessing the database can become a mystery. Developers who just understand how to use Spring Data JPA do not understand the complexities of JDBC and Hibernate.
You will start this course with a basic demonstration of Spring Data JPA. In this section you will learn how to work with a H2 in-memory database.
You'll see how easy it is to work with Spring Data JPA. You will also begin to understand how the Hibernate interaction is being abstracted away.
Since JPA is the Java API for working with Relational Databases, the course takes a closer look at Relational Databases and MySQL specifically.
MySQL is the most popular open source relational database in the world. You will learn how to configure Spring Boot to test with a H2 in-memory database and to run integration tests against a MySQL database. This is a common real-world example leveraging the power of Spring and Hibernate to give you a very flexible environment.
Once we've established a persistent database, we can explore using database migration tools.
Liquibase and Flyway are two very popular database migration tools. Spring Boot supports both options. And you will learn about both options and database security best practices.
By establishing a MySQL database, Spring Boot Integration Tests, and automated database migrations we can use Test Driven Development to explore the features of JDBC and Hibernate.
In the course you will learn:
What is the DAO pattern, and how to implement it using JDBC, Spring's JDBCTemplate, and Hibernate
Relational Database Principles
Schema Creation in MySQL
Schema Generation using Hibernate
Database Migrations using Liquibase
Database Migrations using Flyway
Database Integration Testing using Spring Boot and JUnit 5
Defining Primary Key's with Hibernate
Hibernate Criteria Queries
Named JPA Queries
Spring Data JPA query methods
Spring Data JPA @Query Annotation
Entity Relationships - One to One, One to Many, Many to One, Many to Many
Embedded Types
Natural Keys
Composite Keys
Spring Data JPA Query Methods
Paging and Sorting
Database Transaction Management
Database Fetch Operations
Data Validation
JPA Inheritance
Hibernate Interceptors and Listeners
JPA Callbacks
Legacy Database Mapping
Using Multiple Data Sources
Spring Data REST
Learn Hibernate and Spring Data JPA - Enroll today!