spring data jpa and jpa implementation - spring

As we know that, spring data jpa just adds extra layer on jpa provider. Spring community provides some spring data jpa starter example here
https://spring.io/guides/gs/accessing-data-jpa/#initial
I didn't see any jpa provider used in this example, how could that happen?
Thanks

Spring boot provide jpa
For example, if you want to use Spring and JPA for database access, it is sufficient if you include spring-boot-starter-data-jpa dependency in your project.

Related

Using spring boot JPA features in plain Java project

I want to have a plain java project making use of spring boot JPA support, like JpaRepository, to make a library which I can inject into other spring boot projects for database operations.
Is it possible?

Spring JPA - require JDBC and Hibernate Jar's on class path

Am new to the spring frameworks ,Iam planning to create a Spring Rest application with JPA . am using Mysql database .
I have downloaded the Spring initializer with Web and JPA as dependdencies with Maven. but while Maven install am getting error asking for MYSQL connector jar , so i have adde the maven enetry for the same , on the second try it asking for the hibernate jar .
So am confused like what is the spring-boot-starter-data-jpa dependency doing ? if we need to add the jars into class path , then what is the use of spring-boot-starter-data-jpa ?
spring-boot-starter-data-jpa is a combination of Spring Boot, which itself consists of the Spring framework core and is meant for rapid stand-alone application development, and Spring Data JPA which is Spring's own opinionated abstraction of JPA. It's basically just an interface with a few convenience classes, you still need to supply the JDBC driver for the corresponding database (MySQL in your case) and an actual ORM implementation (the layer that translates your database rows to Java objects and gives you CRUD functionality).

Spring Boot JPA with not a well known database

I am trying to write Spring Boot application to connect to a Teiid database, I want to use JPA layer on it. I have configured the JDBC Data Source, but since this not well-known database in Spring JPA libraries do not autodetect this source. I have manually setup "spring.jpa.*" properties too. I do have a Hibernate dialect for this database, and it is on the classpath.
So, how does one need to configure JPA layer for a not well-known database in Spring Boot? Thank you for your time.
Ramesh..
This is fairly well defined in the Spring Boot documentation.
You can set this explicitly in the application.properties file
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Is Spring Data JPA a JPA implementation?

I am trying to "really" understand Spring Framework. I have got some fair understanding of Spring Core (DI), and Spring MVC.
For data part, I am now focussing on Spring Data JPA. As I understand, JPA is a standard specification, for which there are multiple implementations, Hibernate being the famous one.
Now, when I started Spring Data JPA, I was under the impression that Spring Data JPA is an independent implementation of JPA specification. It turned out that I am wrong.
If I understood correctly, Spring Data JPA is an abstraction layer provided by Spring, which internally uses other JPA provider (Example Hibernate), so typically it is like this:
Application ---> Spring Data JPA --> Hiberate --> JDBC ----> DB
Is my understanding correct? If so isn't Spring Data JPA misleading? It is NOT a JPA provider in itself, it is just an abstraction layer, which works on top of other JPA provider.
I am not sure if I really understand Spring framework or it is a complex framework altogether?
Can anyone please help me understand it?
I don't think it's misnamed (disclaimer: I am the project lead). All Spring Data projects list the store or API they're based on in their name. Spring Data JPA is basically Spring Data for JPA, just like Spring Data MongoDB is Spring Data for MongoDB, just like Spring Batch is Spring for batch applications, Spring Integration is Spring for integration projects.
Do correct your dependency graph for JPA:
Application -> Spring Data JPA -> JPA <- Hibernate -> JDBC -> DataSource
-> — uses
<- — implements
The same for MongoDB:
Application -> Spring Data MongoDB -> MongoDB Java driver -> MongoDB
etc. I'd still be interested where exactly you got the impression that Spring Data JPA is an implementation of JPA as neither the project page nor the reference documentation state that anywhere. In fact, especially the project page is very explicit about what functionality the project provides. Also, it might help to study the description of the umbrella project, which tries to set some fundamental context for all the modules contained in it.

Spring data required hibernate or not

I have one doubt about implementation of spring data, have basic knowledge about spring data.
I understand JPA and Hibernate, how it work. Hibernate provide the implementation for JPA.
My questions, Can we work alone with Spring data to persist data in mysql or we need some provider like hibernate or toplink etc for midsize application
The structure is as follows:
Spring Data JPA
|
JPA
|
Hibernate
You need Hibernate as an JPA implementation, but from your perspective you should only see Spring Data JPA.
When designing your entities if you make sure that you use only annotations from the javax.persistence package you will not depend on one concrete JPA implementation (in this case Hibernate) but theoretically you could swap Hibernate for EclipseLink or something else.

Resources