Hibernate Reactive 中文操作指南

Preface

Hibernate Reactive 是一个用于 Hibernate ORM 的反应式 API,支持无阻塞的数据库驱动程序和一种与数据库进行交互的响应式风格。

Hibernate Reactive is a reactive API for Hibernate ORM, supporting non-blocking database drivers and a reactive style of interaction with the database.

Hibernate Reactive 的目的是在一个响应式编程环境中使用,例如 Vert.x,在那里与数据库的交互应以无阻塞的方式进行。持久性操作通过构建一个响应式流来进行协调,而不是通过在过程化 Java 代码中直接调用同步函数来协调。响应式流使用 Java _CompletionStage_s 或 Mutiny _Uni_s 和 _Multi_s 链条来表示。

Hibernate Reactive is intended for use in a reactive programming environment like Vert.x, where interaction with the database should occur in a non-blocking fashion. Persistence operations are orchestrated via the construction of a reactive stream rather than via direct invocation of synchronous functions in procedural Java code. The reactive stream is represented using a chain of Java _CompletionStage_s or Mutiny _Uni_s and _Multi_s.

像 JDBC、JPA 和 Hibernate ORM 这样的 Java 持久性框架设计为使用阻塞式 IO 与数据库进行交互,因此不适合在响应式环境中使用。据我们所知,Hibernate Reactive 是第一个真正的 ORM 实现,旨在利用无阻塞数据库客户端。支持 PostgreSQL、MySQL、DB2、SQL Server、Oracle 和 CockroachDB 的 Vert.x 客户端开箱即用,尽管架构不限于这些驱动程序。

Java persistence frameworks like JDBC, JPA and Hibernate ORM were designed to use blocking IO for interaction with the database, and are therefore not appropriate for use in a reactive environment. As far as we know, Hibernate Reactive is the first true ORM implementation designed to take advantage of non-blocking database clients. Out of the box, the Vert.x clients for PostgreSQL, MySQL, DB2, SQL Server, Oracle, and CockroachDB are supported, though the architecture is not limited to these drivers.

这种编程范式有可能在某些运行时场景中提高可扩展性并更可控地降低峰值负载状况下的性能损耗。但是,通常来说,人们不应期望在所有性能测试中立即可见性能提升。实际上,很多程序不会从这种编程模型中获益,而从中受益的程序可能也只能在非常特定的负载场景中获益。

This programming paradigm holds the potential for improved scalability, and more controlled degradation under peak load, in some runtime scenarios. However, in general, one should not expect to see an immediate performance gain in all performance tests. Indeed, many programs will not benefit from the programming model, and those which do benefit might only benefit in very specific load scenarios.