Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data vs Spring Data JPA vs JdbcTemplate

I was confident that Spring Data and Spring Data JPA refers as same, but then I watched a tutorial on youtube about Spring Data and he is using JdbcTemplate in that tutorial. So I got confused there.

I want to clarify that what is difference between Spring Data and JdbcTemplate? JdbcTemplate and Spring Data JPA are parts of Spring Data?

like image 800
Noor Rehman Avatar asked Sep 27 '18 08:09

Noor Rehman


3 Answers

JdbcTemplate is part of the Spring Framework itself.

Spring Data is the project which consists of multiple sub-projects where Spring Data JPA is one of those sub-projects. Spring Data and the sub projects build on top of the Spring Framework.

like image 150
M. Deinum Avatar answered Oct 22 '22 05:10

M. Deinum


Use Spring JdbcTemplate if you don't want to access your database schema via a domain model. Using JPA you need to make sure that database schema maps correctly to the domain model.

Performance is almost similar at both spring JdbcTemplate and JPA.

JPA is the Java Persistence API, which is Java's standard API for object-relational mapping.

The Spring Framework consists of a collection of projects, and one of these projects is Spring Data.

The goal of Spring Data is to make it easier to work with different kinds of databases, from traditional relational databases to NoSQL databases. Spring Data supports JPA via the Spring Data JPA subproject.

like image 21
akingokay Avatar answered Oct 22 '22 05:10

akingokay


Here is one of my experienced colleague's recommendation:

To determine which technology to use, this is the order he prefers:

  1. Use standard JPA methods for a straight forward solution - with Mappings, you can do joins seamlessly, accelerates the dev process and error handling is straight forward.
  2. Use JPA Native query if you want to remove the JPA overhead.
  3. USE JPA result set mappings for complex join queries and custom object mappings.....
  4. Use JDBC template if performance is the sole goal - Overheads : dev process is slow as you have to write your own code and error handling mechanism..
like image 36
stoneshishang Avatar answered Oct 22 '22 07:10

stoneshishang