SlideShare ist ein Scribd-Unternehmen logo
1 von 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.
•

Weitere ähnliche Inhalte

Ähnlich wie Spring data jpa are used to develop spring applications

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 

Kürzlich hochgeladen (20)

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

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. •