8

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?

Noor Rehman
  • 113
  • 1
  • 5

3 Answers3

11

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.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • So there is nothing relates to `JdbcTemplate` and `Spring Data`? – Noor Rehman Sep 27 '18 at 08:44
  • It depends on how you look at it. I suspect that when using Spring Data JDBC (a new addition to the family) that internally will use `JdbcTemplate`. However `JdbcTemplate` has nothing related to Spring Data, Spring Data (depending on the sub project) might be related to `JdbcTemplate`. – M. Deinum Sep 27 '18 at 08:45
6

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.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
akingokay
  • 83
  • 4
2

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

UPDATE:

  1. If company is switching to different Database that uses slightly different SQL syntax. using JDBC template will add a lot of work on tweaking the SQL to new database because it only works on the previous database.

    However, if user used JPA, they don't have to touch the query when switching database. Saves a ton of work.

stoneshishang
  • 433
  • 4
  • 11