2

I am trying to build a REST application that may one day be used by potentially millions of clients. Keeping that in mind, we expect a lot of requests to come in together. I am wondering if it will be apt to use Hibernate or spring-flux for this. Our database model is highly relational and hence we have had to reject mongo and other non-relational databases. A few questions I have are:

  1. Can spring-webflux and hibernate be used together?
  2. If the answer to question 1 is No, does spring-flux have a caching feature like hibernate?
  3. If the answer to question 1 is No, will spring flux's non blocking approach be faster than hibernate consistently over time?
  4. What could be some benefits of spring-flux/hibernate that I might be missing to consider?
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
worldbeater
  • 321
  • 1
  • 4
  • 10

2 Answers2

6
  1. Can spring-webflux and hibernate be used together?

Yes of course. BUT the currently Hibernate is blocking-IO so you loose the non-blocking reactive character of spring-webflux. Oliver Gierke (Spring Data project lead) recently announced a reactive Java database connectivity (https://github.com/r2dbc), but this is currently not available.

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

This question is already solved in an other Stack Overflow question: Spring Webflux and @Cacheable - proper way of caching result of Mono / Flux type

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

This question is hard to answer in front. General I/O related stuff is more "expensive" and will drain your performance.

rieckpil
  • 10,470
  • 3
  • 32
  • 56
  • If my application is build using Spring mvc and hibernate and now I switch from spring mvc to spring webflux, can it badly affect my application? For the existing code, I don't want that to be reactive. I just want some new REST endpoints to be reactive. – The Coder Nov 08 '20 at 17:19
2

you can use both R2DBC & Hibernate Reative. But if you are migrating from hibernate based project to webflux, I recommended you to use the Hibernate Reactive. it's all same as the old hibernate and you can use all of the native hibernate annotations, except some minor changes that you can find in the Document.

Issa Khodadadi
  • 917
  • 7
  • 19