Spring Data JPA如何提供数据访问接口而不是休眠数据访问层 [英] How Spring Data JPA provide Data Access Interface instead of hibernate Data Access Layer

查看:74
本文介绍了Spring Data JPA如何提供数据访问接口而不是休眠数据访问层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我探索hibernate JPA实现时,我想到了使用hibernate和创建数据访问层以将数据读取和插入数据库以及从数据库插入数据的想法.现在我在项目中使用spring + spring数据JPA + Hibernate进行某些CRUD操作.我想到了数据JPA的作用是提供CRUD存储库以供数据库访问,而不是使用Hibernate DAO.我这样使用CRUD存储库,

When When I explored hibernate JPA implementation , I got the idea of working with hibernate and creation of data access layer for fetching and inserting data into and from database. Now I am using spring + spring data JPA + Hibernate for some CRUD operation in my project.I got the idea of role of data JPA for providing the CRUD Repository for database access instead of hibernate DAO.I used my CRUD repository like this,

package com.central.repository;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.central.model.*;
public interface DriverRepository extends CrudRepository<Driver, Integer> {

Driver findById(Integer id);
}

在这里,我从数据JPA的"CrudRepository"存储库扩展而来.当我使用此方法时,数据JPA如何为我的界面提供存储库?它们是如何内置的,为我提供findAll(),save()和delete()存储库方法?实际上,我对JPA数据如何为我的界面提供存储库的作用感到怀疑?以及Data JPA如何与hibernate通信以提供这些存储库实现?有人可以指导解决Data JPA与Hibernate JPA实现通信的核心概念吗?

Here I am extends from data JPA's "CrudRepository" repository. When I am using this how the data JPA provides a repository for my interface? How they are inbuilt providing findAll(), save() and delete() repository method for me? Actually I have doubt in the role of how data JPA provides the repository for my interface? And how Data JPA communicate with hibernate for providing these repository implementation?.Can anyone guide to resolve the core concept of Data JPA communicating with Hibernate JPA implementation?

推荐答案

Spring Data为该接口创建一个代理,并且为每种方法尝试不同的策略来查找/创建该方法的实现.

Spring Data creates a Proxy for the interface and for each method tries different strategies for finding/creating an implementation of the method.

CrudRepository的方法在

The methods of CrudRepository are implemented in the SimpleJpaRepository for other methods objects get created based on annotations, parameter and return types and the method name which then get invoked by the proxy.

Wiki文章基本概念可能会有所帮助.

There is a wiki article about the basic concepts that might be helpful.

这篇关于Spring Data JPA如何提供数据访问接口而不是休眠数据访问层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆