Spring Data JPA tutorial - Unboxing Spring Data JPA Magic | Spring Boot | JPA | MySQL | Hibernate

preview_player
Показать описание
In this video, we will unbox the magic of spring data jpa. The Goal here is to understand how Spring Data JPA works internally.

This spring data jpa tutorial will give a step-by-step walkthrough on
1. Build a spring project
2. Configuring Hibernate / JPA / Spring / MYSQL with our Java spring project.
3. Doing CRUD operation with Spring Data JPA
4. Once done, Converting the spring project to Spring Boot
5. Explore spring data jpa with spring boot
6. How spring data JPA works internally

If you want to build a spring boot project that connects to a database, the first thing you will create is a data source.

Datasource in Java holds the connection objects. We can use a DriverManagerDatasource in spring to create a datasource object.

Once the Datasouce setup is done, we can create a EntityManager, which will help us with CRUD operation. EntityManager manages our entities (alternatively called persistence context) and provides a wide range of methods, like persist, remove, find, merge,findAll, etc. This will help us to save, delete, update, and query data from a database.

To create an EnityManager, we can create an EntityManagerFactory first. We only can create an EntityManager from an EntityManagerFactory. In Spring, we need a LocalcontainerEntityManagerFactoryBean to initalize an entity manager factory.

Once the LocalcontainerEntityManagerFactoryBean is set up, then it's time to set up a TransactionManager (PlatformTransactionManager). We can use the JpaTransactionManager to feed it the entity manager factory object to have a fully functional connection setup.

In our DAO, We can use now use an EntityManager with a @PersistenceContext annotation. This will enable us to call the API methods to do CRUD operation.

We can use a @Transactional Annotation on top of our API method to activate and begin/commit the transaction.

Spring Data JPA enables us to automatic repository creation. With the @EnableJpaRepositories we no longer need to write repository classes and the basic CRUD methods to perform data manipulation.
Spring Data JPA will do it all and allows us to have a fully functional CRUD Repository just by extending JpaRepository.

When our custom repository interface extends JpaRepository, it inherits different methods from its super interfaces (CrudRepository, ListCrudRepository, Repository). These methods' implementation is generated in runtime by Spring. Spring Generates this implementation class by using JDK dynamic proxy / AOP proxy.

Data Jpa configuration is so easy when it comes to Spring Boot. We have a one-stop solution to add all the dependencies. We can use a spring boot starter project called "spring boot starter data jpa," and it brings in all the different dependencies that we need to develop a JPA application with spring boot. For MySQL db, we can just add the MySQL driver, and we are ready to go.

We may need to use @EntityScan and @EnableJpaRepositories to scan our Entities and Repository classes.

Let's explore all these concepts in this video! Let's jump right in.

Timestamp
--------------

Introduction - 00:00:00
Build a Maven project - 00:05:34
Building an Entity - 00:07:00
Setting up Repository and EntityManager - 00:13:50
LocalContainerEntityManagerFactoryBean and DataSource setup- 00:23:36
Introducing Hibernate - 00:47:56
Uses of @PersistenceContext - 00:56:42
@Transactional / TransactionManager setup - 01:02:27
Introducing JpaTransactionManager - 01:06:00
EntityManager persist method in action (save) - 01:13:00
Introducing Spring Data JPA - 01:20:00
findAll() implementation with JPA - 01:24:26
Why Spring Data JPA: The Need - 01:29:51
@EnableJpaRepository - 01:37:01
Doing CRUD with Spring Data JPA - 01:38:20
spring data jpa with spring boot - 01:46:19
Spring Boot data jpa autoconfiguration - 01:53:07
@EntityScan - 01:59:04
What's inside the spring-boot-starter-data-jpa dependency?
Activating show-sql in Spring / Spring boot app -02:05:34
The End - 02:07:02

#springdatajpa #springboot #jpa #hibernate

For More free/paid courses visit

LINKS AND FREE LEARNING RESOURCES
========
Watch my new mock interview series for java developers

Watch Spring boot Hot topics

Java Interview / Question and Answer series

spring core

spring mvc

spring mvc intermediate

For more courses visit

you can ask for support in my website forum
Subscribe to my youtube channel
Follow me on Insta
Рекомендации по теме
Комментарии
Автор

Hi. There is a delay in uploading the next scheduled video on Spring Boot Foundation series.
New video coming on this Wednesday. It will be a 10 hours crash course.
Stay tuned to the below playlist for updates

Have a good day !

SeleniumExpress
Автор

I don't know why abhilash is sooo underrated.. hope you will get wat you deserve..❤❤

Ramesh-reeu
Автор

You are the first person on youtube that deliver this type of content. Hats off👏🙌

chintu
Автор

Nice vidoe !
First time saw such in depth analysis on jpa

Mohamed-ufjh
Автор

First time saw such in depth analysis on jpa

baidyanathpanda
Автор

Fabulous tutorial, invaluable ...Thanks Abhilash

akashpisal
Автор

Thanks a ton!! This is very awesome and so much informative

LeoLeo-nxgi
Автор

Awesome vedio ❤, I don't think any book gives this much knowledge on Springboot, In single vedio I got know difference between spring and springboot, multiple data base configuration, etc ❤

unemployedcse
Автор

Nice to meet you!so interesting shots!Selenium- 💫

eprohoda
Автор

Thank you very much spring boot guru ji 🙏🙏🙏

vinotech
Автор

Vedio super information macha 🎉 it helps alot for all of us

csrchandra
Автор

100th like by me, great job abhilash.

DurgaShiva
Автор

Hi Selenium,
One Request, Can you guide or make videos on one to one and other relationship, Where when and which scenario approach should follow to join the tables.

xoojvsp
Автор

Abhilash, Do you know how to map hibernate entity to postgres json column in Spring boot using data also if possible w/o using any external library

akashpisal
Автор

Hi is it possible to call a oracle function with output parameters using spring Data JPA?

mohammadabrarbaqtiyar
Автор

sir, please make videos on spring boot. I have completed the full spring playlist. please upload ASAP SpringBoot playlist.

kanchanshelke
Автор

sir, can you please make a video on oauth2.0

dileepsimham
Автор

We want videos on hibernate mappings please🙏🙏

RahulVerma-ylbd
Автор

failed to configure a datasource: 'url' attribute is not specified and no embedded datasource could be configured. reason: failed to determine a suitable driver class action: consider the following: if you want an embedded database (h2, hsql or derby), please put it on the classpath. if you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

DeepakSharma-cvtj
Автор

How can we attend your live lectures too?

sanskaari.