
Set up a postgres database with docker by running the postgres image in detached mode, mapping a persistent volume, configuring POSTGRES_USERNAME and POSTGRES_PASSWORD, and exposing port 5432.
install a MySQL database with Docker by running a detached container, mount a persistent volume at /var/lib/mysql/data, and set MYSQL_ROOT_PASSWORD while exposing the database port.
Create a spring boot project via spring initializr, selecting maven and java, with groupId com.alibux coding and artifact jpa, adding Spring Data JPA, postgres driver, mysql driver, and Spring Web.
Connect to a PostgreSQL database using the IntelliJ database tool, download the driver, test the connection, and create a new schema named data_jpa under the public schema.
Learn to set up a MySQL data source in your IDE, configure host and port, test the connection, and ensure your container is running to access the database.
Configure a Spring Data JPA project to connect to a PostgreSQL database using application.yaml, set ddl auto to create drop, enable show sql, and test the connection locally.
Configure spring to connect to a MySQL database by creating a mysql profile, updating jdbc url to include create database if not exists, and running with the mysql profile.
Explore a detailed e-learning database schema with courses, authors, sections, lectures, and 1-to-1 resources, including video and text types through resource inheritance, and learn to implement advanced searches and transactions.
Explore how Hibernate fits as a JPA implementation and how Spring Data JPA abstracts boilerplate, enabling auto-configuration of DAO methods and seamless switching between providers.
Transform a database table into a Java class as an author entity and persist it with Spring Data JPA, using Lombok to generate getters, setters, and constructors.
Learn how to turn a plain Java class into a managed entity with the @Entity annotation, and adapt to jakarta.persistence under Spring Boot 3 and Jakarta EE 9.
Annotate the entity with @Id from jakarta.persistence to define the primary key, enabling Spring Data JPA to create the table and explain using Integer over int for null values.
Explore how the jakarta.persistence GeneratedValue annotation auto-generates primary keys using table, sequence, identity, or auto strategies, with wrapper classes and simple keys.
Explore how Hibernate auto-detects an appropriate id-generation strategy (auto, sequence, or table) across Postgres and MySQL profiles, and observe how tables and sequences are created for the author entity.
Explore how the Hibernate @SequenceGenerator annotation configures sequence-based id generation, including setting the generator name, the sequence name, and the allocation size to control increment behavior.
Switch from sequence to table generation using the @TableGenerator annotation, configuring name, table, and primary key columns, with allocation size set to 1, and observe the id generator table.
Explore the @Column annotation to map fields to database columns, including naming (camelCase to snake_case), unique and nullable constraints, insertable and updatable controls, and settings for length, precision, and scale.
Map Java fields to database columns with @Column, covering naming, length, and nullability. Enforce unique constraints, set nullable, insertable, and updatable properties, and manage created at and last modified timestamps.
Learn to map a Java class to a database table with the @Table annotation, setting the table name to author TBL and configuring schema, catalog, unique constraints, and indexes.
Explore how Spring Data JPA uses repositories as a Java interface abstraction to simplify data access, enabling CRUD operations, predefined methods, and support for pagination and sorting.
Explore how Spring Data JPA repositories abstract the data access layer, reduce boilerplate, and perform create, read, update, and delete operations along with paging and sorting through JPA repository interfaces.
Explore the repositories as code by examining the JPA repository interface and its crude and paging and sorting extensions in Spring Data JPA 3.0, including find all and pageable sorting.
Create a repository for the author entity by extending the Spring Data JPA repository interface, using author and integer as generic types, then insert and test data.
Explore how to create a command line runner bean that runs at application startup, inject a repository, and implement startup logic with a lambda expression to interact with data.
Use Spring Data JPA to insert an author at startup by building the author with Lombok’s builder and all-args constructor, then saving via a repository, as logs confirm the insert.
Explore the entity lifecycle in Spring Data JPA, including transient, persistent, detached, and removed states, the Hibernate session, and how save, detach, and merge move between them.
Explore how to model real-world connections with one-to-one, one-to-many, and many-to-many relationships between entities. Learn how relationships enforce data integrity, reduce redundancy with foreign keys, and boost query performance.
Explore how to implement and compare unidirectional and bidirectional many-to-many relationships between authors and courses, focusing on navigation, integrity, and practical class design.
Create the course entity by defining a Java class named course, annotate it with @Entity, add an id with @Id and @GeneratedValue, and include name and description fields using jakarta.persistence.
Create the lecture entity by defining an integer id and a private string lecture name, then annotate the id field with a generated value for a Spring Data JPA model.
Create the resource entity in the models package by defining id with generated value, name, resource name, size, and URL, and prepare to implement relationships next.
Establish a many-to-many relationship between author and course, with course as the owner and author as the inverse, using a join table with course_id and author_id.
Implement a one-to-many relationship between course and sections in Spring Data JPA, mapping a course to many sections and a section to one course via a join column course ID.
Implement a one to many relationship between section and lecture using one to many and many to one mappings with a join column section id.
Define and implement a one-to-one relationship between lecture and resource in Spring Data JPA, exploring unidirectional and bidirectional mappings, join columns, and foreign keys.
Visualize your Spring Data JPA schema by generating and comparing diagrams of author, course, section, lecture, and resources to verify correct table relationships, including many-to-many joins and one-to-one links.
Explore inheritance in Spring Data JPA with a base resource and video and text subclasses. Compare single table, join table, and table per class strategies, including their pros and cons.
Explore inheritance versus composition in object oriented design, emphasizing composition over inheritance for flexibility and easier maintenance, and learn when to apply inheritance strategies effectively.
Use a mapped superclass to share auditing fields across entities via a base entity with created at, last modified at, created by, and last modified by, extending all entities.
Explore inheritance in a class diagram by creating video, file, and text entities sharing a resource base, using Lombok and super builder, and examining inheritance strategies in Spring Data JPA.
Configure single table inheritance with a discriminator column named resource type, assign V, F, T for video, file, and text, and auto-populate the discriminator when persisting children.
Demonstrate the single table strategy with a video repository, persisting a video, and observing the resource table's discriminator value for video, file, and text.
Apply the joined table strategy to map each subclass to its own table with a foreign key pointing to the base table, enabling subclass-specific queries while increasing schema complexity.
Explore the table per class strategy in Hibernate, where each concrete subclass maps to its own table, enabling efficient queries at the cost of more tables and a complex schema.
Leverage polymorphic queries by querying the base resource entity to fetch resources, while using the annotation with polymorphism type explicit to exclude unwanted subclasses and avoid the background union.
Learn to model composite primary keys with embedded IDs and embeddable annotations in spring data jpa, using username and order date as a unique embedded key for an order table.
Create an embedded id in spring data jpa by defining an embeddable order id with username and order date, placing it in an embedded package, and using jakarta persistence embeddable.
Create an order entity with a composite primary key by using an embedded order ID, annotations for entity and embedded ID, and implementing serializable.
Build an order entity with an embedded id as a composite primary key, composed of order date and username, implement serializable, and use the table annotation to avoid reserved keywords.
Create an embeddable address class and embed it into the order entity to store delivery address in the same table, enabling reuse across entities with Lombok annotations.
Embed an address as an embeddable class inside an order using the @Embeddable and @Embedded annotations, with attribute overrides to map fields in the order table.
Explore how Spring Data JPA derives queries from repository method names to perform dynamic read, count, and delete operations, with examples like find by last name and ignore case.
Learn how to write find all by methods in Spring Data JPA, using list return types, interface-based repositories, and autocompletion for first name and age queries.
Explore how to use Spring Data JPA FindBy methods to query authors by first name, with case-insensitive matching, contains, starts with, ends with, and in lists.
Add the Java Faker dependency to a Spring Data JPA project and enable the command line runner to generate fake author data into the author table via pom.xml updates.
Insert fake data by looping 50 times to generate first name, last name, age, and unique email with a faker, then persist data by updating configuration and restarting the application.
Engage in a hands-on exercise by testing the generated repository methods in the author repository using a command line runner to validate find all by methods.
Mastering spring data jpa demonstrates updating author data by saving with an existing id to trigger merge, update, or insert, and shows bulk age updates via a query.
Update author records by using a @Modifying query with @Query, make it transactional, and execute bulk updates to set age based on id filters.
Explore named queries in Spring Data JPA to encapsulate, centralize, and reuse query logic, improve readability, and boost startup validation and performance, while knowing when dynamic queries are preferable.
Learn how to create and use named queries in JPA, including @NamedQuery and named native queries, pass age parameters, and fetch authors via repository methods.
Learn to update author data with @NamedQuery by defining a modifying, transactional update and passing an age parameter. Understand how named queries can be organized with @NamedQueries.
Course description
Embark on a comprehensive journey through the world of Spring Data JPA, and become an expert in creating high-performance, data-driven applications. This in-depth course is tailored for developers seeking to master Spring Data JPA, covering everything from basic concepts to advanced techniques. By enrolling in this course, you will unlock the full potential of Spring Data JPA and gain the confidence to tackle complex real-world challenges.
Key topics covered in this course include:
Setting up your development environment: Learn how to connect to MySQL and PostgreSQL databases using Docker, ensuring a smooth and practical learning experience.
Exploring Spring Data JPA fundamentals: Dive into the core concepts of Spring Data JPA, including entities, primary keys, generation types, columns, and tables. Get hands-on experience through practical examples that solidify your understanding of these essential annotations.
Mastering repositories and the entity lifecycle: Understand the repository hierarchy, entity lifecycle, and how to leverage the power of Spring Data JPA to manage your data efficiently.
Unraveling entity relationships: Delve into various relationship types, such as one-to-one, one-to-many, and many-to-many, while learning best practices for modeling and managing complex relationships between entities.
Understanding inheritance: Gain a deep understanding of inheritance strategies in Spring Data JPA and how to model and query hierarchical data effectively.
Leveraging embedded IDs and entities: Discover how to use embedded IDs and entities to model composite primary keys and embeddable types, enhancing the reusability and maintainability of your code.
Querying data: Master the art of querying data using various techniques, including JPQL, native SQL queries, and the Criteria API.
Named queries: Learn how to use named queries for better organization, maintainability, and performance optimization.
Specification: Unlock the full potential of Spring Data JPA Specifications to create dynamic and type-safe queries, which can be combined and reused for ultimate flexibility and maintainability.
This comprehensive course is designed to provide you with the knowledge and skills necessary to excel in your career as a Spring Data JPA developer. With a balanced mix of theory, hands-on examples, and best practices, you will be well-equipped to create efficient and scalable applications using Spring Data JPA. Enroll today and take the first step towards becoming a Spring Data JPA expert!