How to use Spring JPA with PostgreSQL | Spring Boot

preview_player
Показать описание
In tradition approach, implementing Data Access Layer makes lots of boilerplate of code. Spring JPA is a part of Spring Data, helps us improve our codes and reduce efforts for development and maintenance. Spring JPA supports us the ways to write interface for repositories and custom finder methods, the implementation will be done automatically by Spring Framework.

The tutorial will introduce you how to use Spring JPA with PostgreSQL using Spring Boot.

I. Technology

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.0.RELEASE

II. Overview

1. Goal

2. Project Structure
– Class Customer corresponds to entity and table customer, it should be implemented Serializable.
– CustomerRepository is an interface extends CrudRepository, will be autowired in WebController for implementing repository methods and custom finder methods.
– WebController is a REST Controller which has request mapping methods for RESTful requests such as: save. findall, findbyid, findbylastname.

3. Step to do
– Create Spring Boot project & add Dependencies
– Configure Spring JPA
– Create DataModel Class
– Create Spring JPA Repository Interface
– Create Web Controller
– Create PostGreSQL table
– Run Spring Boot Application & Enjoy Result

III. Practice

1. Create Spring Boot project & add Dependencies
2. Configure Spring JPA
3. Create DataModel Class
4. Create Spring JPA Repository Interface
5. Create Web Controller
6. Create PostGreSQL table
Open pdAdmin III, use SQL Editor and make a queryfor create customer table:

CREATE TABLE customer(
id BIGINT PRIMARY KEY NOT NULL,
firstname VARCHAR(20),
lastname VARCHAR(20)
);

7. Run Spring Boot Application & Enjoy Result
– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results:

Request 1
The browser returns Done and if checking database testdb with table customer, we can see some data rows has been added.

Request 2

Request 3

Request 4

IV. Source Code

================related keywork===============
#jpa postgresql example #jpapostgresqlexample
#jpa postgresql tutorial #jpapostgresqltutorial
#jpa hibernate postgresql #jpahibernatepostgresql
#spring boot jpa postgresql #springbootjpapostgresql
#spring datasource postgresql example #springdatasourcepostgresqlexample
#spring boot postgresql example #springbootpostgresqlexample
#spring boot jpa postgresql #springbootjpapostgresql
#spring jpa tutorial pdf #springjpatutorialpdf
#spring jpa hibernate tutorial or example #springjpahibernatetutorialorexample
#spring jpa tutorial for beginners #springjpatutorialforbeginners
#spring jpa repository tutorial #springjparepositorytutorial
#spring jpa example entitymanager #springjpaexampleentitymanager
#spring jpa integration example #springjpaintegrationexample
#spring jpa vs hibernate #springjpavshibernate
#spring boot jpa #springbootjpa
#spring jpa maven #springjpamaven
#spring boot jpa mysql #springbootjpamysql
#spring boot jpa hibernate #springbootjpahibernate
#spring boot jpa rest #springbootjparest
#spring-boot-starter-data-jpa #spring-boot-starter-data-jpa
#spring boot jpa example #springbootjpaexample
#spring boot postgresql datasource #springbootpostgresqldatasource
#spring boot postgres example #springbootpostgresexample
Рекомендации по теме
Комментарии
Автор

Thanks for the wonderful tutorial, it helped!

artemfedotov
Автор

Thank you very much, you saved my day

sbtest
Автор

Thank you so much!! This helped me alot.

Chilaka_palukulu
Автор

That was really amazing. Learnt a lot. :)

sachinpatil
Автор

Where to(in which package ) create CrudRepository interface and is that built in interface ???pls reply me asap

manojkumarpujari
Автор

But how to configure pg admin?
I have just installed it and couldn't understand what to do next!!!

Adityasngp
Автор

I'm getting below erro
Refreshing data from Spring process: 14272 - - retry no: 3
can someone help. I've same code as shown in the video.

teja
Автор

4:20 where was the testdb from? is that from his own database in his on pgadmin 4

jongale
Автор

Where did you implement the findByLastName method?

jesusromero
Автор

Hi, I am getting error for lastname: Error creating bean with repository

rupalimehandiratta
Автор

@Aditya hope you got how to figure out to run pgadmin

rexsam
Автор

one thing i dont understand is that my password is something else completely, so should my password for when i first installed pgadmin 4 be that or the '123'?, also how does it pick up the tables and values?

jongale