About CrudRepository and Criteria API - spring

I'm new to Spring Boot and now I'm learning to modify data with JPA and Hibernate. I wonder is there any way that I can combine Criteria API of Hibernate with Crud Repository, and add more methods into the repository.

Related

spring data jpa and jpa implementation

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.

What is the difference between JpaRepository and MongoRepository?

I don't know the difference between JpaRepository and MongoRepository.
JPARepository and MongoRepository are technology-specific abstraction of the Spring Data Repositories.
If you are using RDBMS such as MySQL/PostgreSQL, you may use Spring Data Repositories such as JpaRepository.
If using a NoSQL such as Mongo, you will need the MongoReposiroty.

Is there a way to add JPA annotations at runtime to JAXB generated bean classes using Spring Data JPA?

As part of project requirements, where we need to handle certain volume of data through REST call. Customer would call in a REST service, passing in a payload and distributed a jar of JAXB generated bean classes. Now these classes are not Entity beans by itself. Service should be able to use these JAXB objects and persists them as Entities using Spring Data JPA. But this required #Entity and other annotations required for JPA.
Is there a way to let Spring Data JPA know that these are entities and perform CRUD operations using JpaRespository etc? I know couple of options are discussed Separating JPA information from POJO and Is it possible to build a JPA entity by extending a POJO? . But those two are Hibernate specific solution and have control on the source code of the JAXB beans.
But I'm looking at solution more abstract in Spring Data JPA out of box.
Thanks

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