spring data如何根据方法名生成sql? [英] How spring data generate sql according to method name?

查看:37
本文介绍了spring data如何根据方法名生成sql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道spring data jpa可以通过两种方式执行sql.一种是执行@Query包含的sql,另一种是解析方法名并生成sql.我从github克隆了spring data jpa的源代码,想知道spring data如何根据方法名生成sql.但是我找不到与parse方法名相关的类.所以,你能告诉我一些关于如何spring data jpa 关于解析方法名的工作?谢谢

I know spring data jpa can execute sql by two ways.One is execute sql which is included by @Query, the other is parse method name and generate sql. I clone the source code of spring data jpa from github and want to find how spring data generate sql according to method name.But I can't find the class which is related to parse method name.So,could you tell me something about how spring data jpa works about parsing method name?Thanks

推荐答案

这是一个多步骤的过程:

Its a multi-step process:

  1. Spring Data JPA 为存储库接口生成一个代理类.
  2. 代理生成一个PartTree 使用 PartTreeJpaQuery 类.PartTree 类是 Spring Data Commons 模块的一部分,它是特定于存储的 Spring Data 模块(如 Spring Data JPA 模块)的依赖项.
  3. 然后将 PartTree 传递给 JpaQueryCreator 生成 JPA CriteriaQuery 实例.
  4. CriteriaQuery 实例被传递到底层 JPA 提供程序(Hibernate、OpenJPA、EclipseLink 等),然后生成要执行的 SQL.
  1. Spring Data JPA generates a proxy class for the repository interface.
  2. The proxy generates a PartTree instance for each repository method using the PartTreeJpaQuery class. The PartTree class is part of the Spring Data Commons module, which is a dependency for the store-specific Spring Data modules (like the Spring Data JPA module).
  3. The PartTree is then passed to a JpaQueryCreator to generate a JPA CriteriaQuery instance.
  4. The CriteriaQuery instance is passed to the underlying JPA provider (Hibernate, OpenJPA, EclipseLink, etc.) which then generates SQL to be executed.

这篇关于spring data如何根据方法名生成sql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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