我可以将 SpringWebflux 与休眠一起使用吗?

Can I use SpringWebflux with hibernate or not?

我正在尝试构建一个 REST 应用程序,有一天可能会被数百万潜在客户使用。牢记这一点,我们预计会收到很多请求。我想知道它是否适合为此使用 Hibernate 或 spring-flux。我们的数据库模型是高度相关的,因此我们不得不拒绝 mongo 和其他非关系数据库。我有几个问题:

  1. spring-webflux和hibernate可以一起使用吗?
  2. 如果问题1的答案是否定的,那么spring-flux有像hibernate一样的缓存功能吗?
  3. 如果问题 1 的答案是否定的,随着时间的推移,springflux 的非阻塞方法会比 hibernate 更快吗?
  4. 我可能没有考虑到 spring-flux/hibernate 的哪些好处?
  1. Can spring-webflux and hibernate be used together?

当然可以。 但是 当前的 Hibernate 是阻塞 IO,所以你失去了 spring-webflux 的非阻塞反应特性。 Oliver Gierke(Spring 数据项目负责人)最近宣布了反应式 Java 数据库连接 (https://github.com/r2dbc),但目前尚不可用。

  1. If the answer to question 1 is No, does spring-flux have a caching feature like hibernate?

这个问题已经在另一个 Stack Overflow 问题中解决了:

  1. If the answer to question 1 is No, will spring flux's non blocking approach be faster than hibernate consistently over time?

前面这个问题不好回答。一般 I/O 相关的内容更多 "expensive" 并且会耗尽你的表现。

您可以同时使用 R2DBCHibernate Reative。 但是 如果您要从基于 hibernate 的项目迁移到 webflux,我建议您使用 Hibernate Reactive。它与旧的 hibernate 完全相同,您可以使用所有本机 hibernate 注释,除了您可以在 Document.

中找到的一些小更改