JPA Support
Spring Integration 的 JPA(Java Persistence API)模块提供了使用 JPA 执行各种数据库操作的组件。
Spring Integration’s JPA (Java Persistence API) module provides components for performing various database operations using JPA.
你需要将此依赖项包含在你的项目中:
You need to include this dependency into your project:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jpa</artifactId>
<version>{project-version}</version>
</dependency>
compile "org.springframework.integration:spring-integration-jpa:{project-version}"
必须通过一些特定于供应商的实现包含 JPA API,例如 Hibernate ORM Framework。
The JPA API must be included via some vendor-specific implementation, e.g. Hibernate ORM Framework.
提供了以下组件:
The following components are provided:
可以通过向这些组件发送和接收消息,对目标数据库执行 select
、create
、update
和 delete
操作。
These components can be used to perform select
, create
, update
, and delete
operations on the target databases by sending and receiving messages to them.
JPA 入站通道适配器允许您轮询并检索(select
)数据库中的数据,而 JPA 出站通道适配器允许您创建、更新和删除实体。
The JPA inbound channel adapter lets you poll and retrieve (select
) data from the database by using JPA, whereas the JPA outbound channel adapter lets you create, update, and delete entities.
您可以将用于 JPA 的出站网关用于将实体持久化到数据库,让您继续流程并在下游执行更多组件。同样,您还可以使用出站网关从数据库中检索实体。
You can use outbound gateways for JPA to persist entities to the database, letting you continue the flow and execute further components downstream. Similarly, you can use an outbound gateway to retrieve entities from the database.
例如,您可以使用出站网关在请求通道上接收带有 userId
有效负载的 Message
,对数据库进行查询,检索用户实体,并将其向下传递以进行进一步处理。
For example, you may use the outbound gateway, which receives a Message
with a userId
as payload on its request channel, to query the database, retrieve the user entity, and pass it downstream for further processing.
认识到这些含义差异,Spring Integration 提供两个单独的 JPA 输出网关:
Recognizing these semantic differences, Spring Integration provides two separate JPA outbound gateways:
-
Retrieving outbound gateway
-
Updating outbound gateway