5

I currently have a Vert.x codebase. I was using Golang, but Golang kinda sucks and doesn't have a good ORM. But apparently, Vert.x doesn't have a good ORM either, primarily because Vert.x is non-blocking and most ORMs for Java were based on blocking APIs.

Anyhow, I have a specific question - I read that Hibernate/JPA could be used with Vert.x - what we could do is put the Hibernate calls in a different Verticle and then it would be non-blocking.

Is that a good idea? Can someone show an example of doing that with 2 different Vert.x verticles?

If it's not a good idea, what might be a good ORM to use? Naked SQL calls sounds cool at first, but for migrations and stuff, might get kinda crazy.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • this is a start: https://github.com/vert-x3/vertx-examples/blob/master/spring-examples/spring-example/README.adoc – Alexander Mills Jan 27 '19 at 03:29
  • 2
    You can wrap your Hibernate calls with execute blocking or encapsulate them in a worker verticle. There's also [vertx-jooq](https://github.com/jklingsporn/vertx-jooq). If you work with Postgres, then you can get fully reactive as vertx-jooq supports the Reactive Postgres Driver. – tsegismont Jan 27 '19 at 10:02
  • @tsegismont thx yeah right now I am using Hibernate and putting the Hibernate stuff in a worker verticle and wrapping that shiz with executeBlocking, not sure how performant it is, but I guess we'll find out. I visited the link you dropped just now and I don't see the Reactive Postgres Driver in there, do you? – Alexander Mills Jan 27 '19 at 10:04
  • @tsegismont maybe it's this one? https://github.com/jklingsporn/vertx-jooq/tree/master/vertx-jooq-classic-reactive – Alexander Mills Jan 27 '19 at 10:04
  • See https://github.com/jklingsporn/vertx-jooq#new-in-version-40 : "Starting from this version on, vertx-jooq adds support for this winning, high performance postgres driver." – tsegismont Jan 28 '19 at 09:19
  • you don't need executeBlocking if you move the Hibernate code to a worker verticle. – tsegismont Jan 28 '19 at 09:20

1 Answers1

7

@tsegismont, as he usually does, already provided a good solution in the comments. I would like just to clarify the following sentence:

I read that Hibernate/JPA could be used with Vert.x - what we could do is put the Hibernate calls in a different Verticle and then it would be non-blocking

There is a true and a false part there:

Hibernate/JPA could be used with Vert.x

True. By putting blocking code in a worker verticle you don't block Vert.x event loop, and that allows frameworks based on JDBC to work with Vert.x

put the Hibernate calls in a different Verticle and then it would be non-blocking

False. You don't make Hibernate non-blocking. JDBC is blocking in it's nature, and there's not much that can be done to solve that (although R2DBC is a nice initiative). You'll use the same thread pool you were using before, with the same limitations.

Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40
  • yeah, my conclusion was trying to pair Hibernate with Vert.x was just no bueno. Using sync i/o is inefficient even if you multiplex it etc. – Alexander Mills Jan 28 '19 at 20:22
  • While reactive programming gains adoption and a lot of (async/reactive) drivers emerge that support various databases, there is no standardized API yet that would allow client library authors to craft object-mapping frameworks. That being said, each eco-system seems to come up with its own feature set and there is a need for a standard API for non-blocking, ideally reactive data access. You might want to leave your vote in https://github.com/reactiverse/reactive-pg-client/issues/249 to support R2DBC in Reactiverse's PgClient. The number of interested clients (MyBatis, Spring, JDBI) is growing. – mp911de Mar 02 '19 at 21:11