SlideShare uma empresa Scribd logo
1 de 26
Drawbacks of JDBC API
• when JDBC API is used for database operation, the developer needs to provide
a lot of data access code before and after the execution of a query. This
increases the code size and it becomes difficult to maintain and make changes.
• All the exceptions thrown in JDBC have checked exceptions that require try-
catch blocks in the code. This also makes the code difficult to read and
maintain.
• If the database connection is not closed in an application, it will lead to
resource leakage.
Limitations of JDBC API
• A developer needs to open and close the connection.
• A developer has to create, prepare, and execute the statement and also
maintain the resultset.
• A developer needs to specify the SQL statement(s), prepare, and execute
the statement.
• A developer has to set up a loop for iterating through the result (if any).
• A developer has to take care of exceptions and handle transactions.
• The above limitations can be solved with the technologies Spring ORM.
Why Spring Data JPA?
• The Programmer has to write the code to perform common database
operations(CRUD operations) in repository class implementation.
• A developer can define the required database access methods in the
repository implementation class in his/her own way, which leads to
inconsistency in the data access layer implementation.
• So in this course, we will see how Spring Data JPA helps us to
overcome these limitations.
SpringBoot
Spring is a lightweight framework for developing enterprise applications. But using
Spring for application development is challenging for developer because of the
following reason which reduces productivity and increases the development time:
1. Configuration
Developing a Spring application requires a lot of configuration. This configuration also
needs to be overridden for different environments like production, development, testing,
etc. For example, the database used by the testing team may be different from the one
used by the development team. So we have to spend a lot of time writing configuration
instead of writing application logic for solving business problems.
contd
2. Project Dependency Management
When you develop a Spring application you have to search for all
compatible dependencies for the Spring version that you are using and
then manually configure them. If the wrong version of dependencies is
selected, then it will be an uphill task to solve this problem. Also for
every new feature added to the application, the appropriate dependency
needs to be identified and added. All this reduces productivity.
So to handle all these kinds of challenges Spring Boot came in the
market.
Spring Boot
Spring Boot is a framework built on top of the Spring framework that helps the
developers to build Spring-based applications very quickly and easily.
The main goal of Spring Boot is to create Spring-based applications
quickly without demanding developers to write the boilerplate configuration.
How Spring Boot works
1.Spring Boot is an opinionated framework
Spring Boot forms opinions. It means that Spring Boot has some sensible defaults which you can
use to quickly build your application. For example, Spring Boot uses embedded Tomcat as the
default web container.
2. Spring Boot is customizable
Though Spring Boot has its defaults, you can easily customize it at any time during your
development based on your needs. For example, if you prefer log4j for logging over Spring Boot
built-in logging support then you can easily make a dependency change in your pom.xml file to
replace the default logger with log4j dependencies.
The main Spring Boot features are as follows:
• Starter Dependencies
• Automatic Configuration
• Spring Boot Actuator
• Easy-to-use Embedded Servlet Container Support
Spring Data JPA- Project Components
The generated project contains the following files:
pom.xml: This file contains information about the project and configuration
details used by Maven to build the project.
Spring Boot Starter Parent and Spring Boot starters: Defines key versions of
dependencies and combine all the related dependencies under a single
dependency.
application.properties: This file contains application-wide properties. Spring
reads the properties defined in this file to configure a Spring Boot application.
A developer can define a server’s default port, server’s context path, database
URLs, etc, in this file.
ClientApplication: Main application with @SpringBootApplication and code to
interact with the end user.
Dependencies
1. pom.xml :
This file contains information about the project and
configuration/dependency details used by Maven to build the Spring
Data JPA project.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.infytel</groupId>
<artifactId>demo-spring-data-JPA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-spring-data-JPA</name>
<description>Demo project for Spring Data JPA with Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Spring Boot Starter Parent
2. Spring Boot Starter Parent:
The Spring Boot Starter Parent defines key versions of dependencies and
default plugins for quickly building Spring Boot applications. It is present in
pom.xml file of application as a parent as follows:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/>
</parent>
Spring Boot starters
One of the starters of Spring Boot is spring-boot-starter-data-jpa. It
informs Spring Boot that it is a Spring Data JPA application.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Configuring database
3.application.properties: This is for adding the database details to the
project (added the necessary details for MySQL DB).
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/sample
spring.datasource.username=root
spring.datasource.password=root
ClientApplication
4.ClientApplication:
The class Client is annotated with @SpringBootApplication annotation
which is used to bootstrap Spring Boot application.
@SpringBootApplication
public class ClientApplication{
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
contd
The class that is annotated with @SpringBootApplication will be
considered as the main class, is also a bootstrap class. It kicks starts the
application by invoking the SpringApplication.run() method. The
developer needs to pass the .class file name of the main class to the
run() method.
contd
contd
contd
• Spring Data is a sub-project of the popular Spring Framework that aims to
simplify data access and persistence for Java applications. It provides a
unified and consistent API for working with different data storage
technologies, such as relational databases, NoSQL databases, and in-
memory databases.
• The architecture of Spring Data consists of the following components:
• 1. Repository: The core component of Spring Data is the repository
interface. It defines a set of methods for CRUD (create, read, update, delete)
operations on a specific domain object. By extending the repository
interface, developers can avoid writing boilerplate code for basic data
access operations.
• 2. Repository Implementation: Spring Data provides default
implementations for the repository interfaces based on the underlying data
storage technology. For example, if you are using a relational database,
Spring Data will generate SQL queries to perform the required operations. I
3.Entity
• In JPA, we can easily insert data into database through entities. The
EntityManager provides persist() method to insert records.
4.Data Source Configuration: Spring Data supports various data
source technologies, and you need to configure the appropriate data
source in your application. This can be done using either XML-based
configuration or Java-based configuration using annotations.
5. Query DSL: Spring Data provides a query DSL (Domain Specific
Language) for defining custom queries. Developers can define queries
using method names in the repository interface, and Spring Data will
automatically generate the necessary query code at runtime.
6. Data Mapping: Spring Data handles mapping of entities to
database tables/documents automatically, based on naming
conventions and annotations. Developers can also customize the
mapping using annotations.
7. Transactions: Spring Data integrates seamlessly with Spring's
transaction management capabilities. You can annotate methods or
classes with the @Transactional annotation to indicate that they
should be executed within a transaction.
Pagination
• Pagination in Spring JPA allows you to retrieve a subset of data
from a database by specifying the page number and the
number of records per page. This is useful when dealing with
large datasets and only needing to display a portion of the data
at a time, such as in a web application.
•

Mais conteúdo relacionado

Semelhante a Spring data jpa are used to develop spring applications

Semelhante a Spring data jpa are used to develop spring applications (20)

Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Spring framework Introduction
Spring framework  IntroductionSpring framework  Introduction
Spring framework Introduction
 
Spring notes
Spring notesSpring notes
Spring notes
 
SSDT unleashed
SSDT unleashedSSDT unleashed
SSDT unleashed
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Oracle Data Integrator
Oracle Data Integrator Oracle Data Integrator
Oracle Data Integrator
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Ibm
IbmIbm
Ibm
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
SPring boot.pptx
SPring boot.pptxSPring boot.pptx
SPring boot.pptx
 
Springboot - A milestone framework in Java Development
Springboot - A milestone framework in Java DevelopmentSpringboot - A milestone framework in Java Development
Springboot - A milestone framework in Java Development
 
Chapter6 web apps-tomcat
Chapter6 web apps-tomcatChapter6 web apps-tomcat
Chapter6 web apps-tomcat
 
Spring Framework Rohit
Spring Framework RohitSpring Framework Rohit
Spring Framework Rohit
 
Synopsis on online shopping by sudeep singh
Synopsis on online shopping by  sudeep singhSynopsis on online shopping by  sudeep singh
Synopsis on online shopping by sudeep singh
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring Boot Whirlwind Tour
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind Tour
 

Mais de michaelaaron25322

Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unitmichaelaaron25322
 
memory Organization in computer organization
memory Organization in computer organizationmemory Organization in computer organization
memory Organization in computer organizationmichaelaaron25322
 
EST is a software architectural style that was created to guide the design an...
EST is a software architectural style that was created to guide the design an...EST is a software architectural style that was created to guide the design an...
EST is a software architectural style that was created to guide the design an...michaelaaron25322
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unitmichaelaaron25322
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java scriptmichaelaaron25322
 
Unit-II AES Algorithm which is used machine learning
Unit-II AES Algorithm which is used machine learningUnit-II AES Algorithm which is used machine learning
Unit-II AES Algorithm which is used machine learningmichaelaaron25322
 
UNIT2_NaiveBayes algorithms used in machine learning
UNIT2_NaiveBayes algorithms used in machine learningUNIT2_NaiveBayes algorithms used in machine learning
UNIT2_NaiveBayes algorithms used in machine learningmichaelaaron25322
 
Spring Data JPA USE FOR CREATING DATA JPA
Spring Data JPA USE FOR CREATING DATA  JPASpring Data JPA USE FOR CREATING DATA  JPA
Spring Data JPA USE FOR CREATING DATA JPAmichaelaaron25322
 
Computer organization algorithms like addition and subtraction and multiplica...
Computer organization algorithms like addition and subtraction and multiplica...Computer organization algorithms like addition and subtraction and multiplica...
Computer organization algorithms like addition and subtraction and multiplica...michaelaaron25322
 
karnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptkarnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptmichaelaaron25322
 
booleanalgebra-140914001141-phpapp01 (1).ppt
booleanalgebra-140914001141-phpapp01 (1).pptbooleanalgebra-140914001141-phpapp01 (1).ppt
booleanalgebra-140914001141-phpapp01 (1).pptmichaelaaron25322
 

Mais de michaelaaron25322 (13)

Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
memory Organization in computer organization
memory Organization in computer organizationmemory Organization in computer organization
memory Organization in computer organization
 
EST is a software architectural style that was created to guide the design an...
EST is a software architectural style that was created to guide the design an...EST is a software architectural style that was created to guide the design an...
EST is a software architectural style that was created to guide the design an...
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
Unit-II AES Algorithm which is used machine learning
Unit-II AES Algorithm which is used machine learningUnit-II AES Algorithm which is used machine learning
Unit-II AES Algorithm which is used machine learning
 
UNIT2_NaiveBayes algorithms used in machine learning
UNIT2_NaiveBayes algorithms used in machine learningUNIT2_NaiveBayes algorithms used in machine learning
UNIT2_NaiveBayes algorithms used in machine learning
 
Spring Data JPA USE FOR CREATING DATA JPA
Spring Data JPA USE FOR CREATING DATA  JPASpring Data JPA USE FOR CREATING DATA  JPA
Spring Data JPA USE FOR CREATING DATA JPA
 
Computer organization algorithms like addition and subtraction and multiplica...
Computer organization algorithms like addition and subtraction and multiplica...Computer organization algorithms like addition and subtraction and multiplica...
Computer organization algorithms like addition and subtraction and multiplica...
 
mean stack
mean stackmean stack
mean stack
 
karnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.pptkarnaughmaprev1-130728135103-phpapp01.ppt
karnaughmaprev1-130728135103-phpapp01.ppt
 
booleanalgebra-140914001141-phpapp01 (1).ppt
booleanalgebra-140914001141-phpapp01 (1).pptbooleanalgebra-140914001141-phpapp01 (1).ppt
booleanalgebra-140914001141-phpapp01 (1).ppt
 
mst_unit1.pptx
mst_unit1.pptxmst_unit1.pptx
mst_unit1.pptx
 

Último

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 

Último (20)

Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Spring data jpa are used to develop spring applications

  • 1.
  • 2. Drawbacks of JDBC API • when JDBC API is used for database operation, the developer needs to provide a lot of data access code before and after the execution of a query. This increases the code size and it becomes difficult to maintain and make changes. • All the exceptions thrown in JDBC have checked exceptions that require try- catch blocks in the code. This also makes the code difficult to read and maintain. • If the database connection is not closed in an application, it will lead to resource leakage.
  • 3. Limitations of JDBC API • A developer needs to open and close the connection. • A developer has to create, prepare, and execute the statement and also maintain the resultset. • A developer needs to specify the SQL statement(s), prepare, and execute the statement. • A developer has to set up a loop for iterating through the result (if any). • A developer has to take care of exceptions and handle transactions. • The above limitations can be solved with the technologies Spring ORM.
  • 4. Why Spring Data JPA? • The Programmer has to write the code to perform common database operations(CRUD operations) in repository class implementation. • A developer can define the required database access methods in the repository implementation class in his/her own way, which leads to inconsistency in the data access layer implementation. • So in this course, we will see how Spring Data JPA helps us to overcome these limitations.
  • 5. SpringBoot Spring is a lightweight framework for developing enterprise applications. But using Spring for application development is challenging for developer because of the following reason which reduces productivity and increases the development time: 1. Configuration Developing a Spring application requires a lot of configuration. This configuration also needs to be overridden for different environments like production, development, testing, etc. For example, the database used by the testing team may be different from the one used by the development team. So we have to spend a lot of time writing configuration instead of writing application logic for solving business problems.
  • 6. contd 2. Project Dependency Management When you develop a Spring application you have to search for all compatible dependencies for the Spring version that you are using and then manually configure them. If the wrong version of dependencies is selected, then it will be an uphill task to solve this problem. Also for every new feature added to the application, the appropriate dependency needs to be identified and added. All this reduces productivity. So to handle all these kinds of challenges Spring Boot came in the market.
  • 7. Spring Boot Spring Boot is a framework built on top of the Spring framework that helps the developers to build Spring-based applications very quickly and easily. The main goal of Spring Boot is to create Spring-based applications quickly without demanding developers to write the boilerplate configuration.
  • 8. How Spring Boot works 1.Spring Boot is an opinionated framework Spring Boot forms opinions. It means that Spring Boot has some sensible defaults which you can use to quickly build your application. For example, Spring Boot uses embedded Tomcat as the default web container. 2. Spring Boot is customizable Though Spring Boot has its defaults, you can easily customize it at any time during your development based on your needs. For example, if you prefer log4j for logging over Spring Boot built-in logging support then you can easily make a dependency change in your pom.xml file to replace the default logger with log4j dependencies. The main Spring Boot features are as follows: • Starter Dependencies • Automatic Configuration • Spring Boot Actuator • Easy-to-use Embedded Servlet Container Support
  • 9. Spring Data JPA- Project Components The generated project contains the following files: pom.xml: This file contains information about the project and configuration details used by Maven to build the project. Spring Boot Starter Parent and Spring Boot starters: Defines key versions of dependencies and combine all the related dependencies under a single dependency. application.properties: This file contains application-wide properties. Spring reads the properties defined in this file to configure a Spring Boot application. A developer can define a server’s default port, server’s context path, database URLs, etc, in this file. ClientApplication: Main application with @SpringBootApplication and code to interact with the end user.
  • 10. Dependencies 1. pom.xml : This file contains information about the project and configuration/dependency details used by Maven to build the Spring Data JPA project.
  • 11. <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven- 4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.infytel</groupId> <artifactId>demo-spring-data-JPA</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo-spring-data-JPA</name> <description>Demo project for Spring Data JPA with Spring Boot</description>
  • 14. Spring Boot Starter Parent 2. Spring Boot Starter Parent: The Spring Boot Starter Parent defines key versions of dependencies and default plugins for quickly building Spring Boot applications. It is present in pom.xml file of application as a parent as follows: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath/> </parent>
  • 15. Spring Boot starters One of the starters of Spring Boot is spring-boot-starter-data-jpa. It informs Spring Boot that it is a Spring Data JPA application. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
  • 16. Configuring database 3.application.properties: This is for adding the database details to the project (added the necessary details for MySQL DB). spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sample spring.datasource.username=root spring.datasource.password=root
  • 17. ClientApplication 4.ClientApplication: The class Client is annotated with @SpringBootApplication annotation which is used to bootstrap Spring Boot application. @SpringBootApplication public class ClientApplication{ public static void main(String[] args) { SpringApplication.run(ClientApplication.class, args); } }
  • 18. contd The class that is annotated with @SpringBootApplication will be considered as the main class, is also a bootstrap class. It kicks starts the application by invoking the SpringApplication.run() method. The developer needs to pass the .class file name of the main class to the run() method.
  • 19. contd
  • 20. contd
  • 21. contd
  • 22.
  • 23.
  • 24. • Spring Data is a sub-project of the popular Spring Framework that aims to simplify data access and persistence for Java applications. It provides a unified and consistent API for working with different data storage technologies, such as relational databases, NoSQL databases, and in- memory databases. • The architecture of Spring Data consists of the following components: • 1. Repository: The core component of Spring Data is the repository interface. It defines a set of methods for CRUD (create, read, update, delete) operations on a specific domain object. By extending the repository interface, developers can avoid writing boilerplate code for basic data access operations. • 2. Repository Implementation: Spring Data provides default implementations for the repository interfaces based on the underlying data storage technology. For example, if you are using a relational database, Spring Data will generate SQL queries to perform the required operations. I
  • 25. 3.Entity • In JPA, we can easily insert data into database through entities. The EntityManager provides persist() method to insert records. 4.Data Source Configuration: Spring Data supports various data source technologies, and you need to configure the appropriate data source in your application. This can be done using either XML-based configuration or Java-based configuration using annotations. 5. Query DSL: Spring Data provides a query DSL (Domain Specific Language) for defining custom queries. Developers can define queries using method names in the repository interface, and Spring Data will automatically generate the necessary query code at runtime. 6. Data Mapping: Spring Data handles mapping of entities to database tables/documents automatically, based on naming conventions and annotations. Developers can also customize the mapping using annotations. 7. Transactions: Spring Data integrates seamlessly with Spring's transaction management capabilities. You can annotate methods or classes with the @Transactional annotation to indicate that they should be executed within a transaction.
  • 26. Pagination • Pagination in Spring JPA allows you to retrieve a subset of data from a database by specifying the page number and the number of records per page. This is useful when dealing with large datasets and only needing to display a portion of the data at a time, such as in a web application. •