Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Hibernate as non-blocking ORM with Vert.x

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.

like image 678
Alexander Mills Avatar asked Jan 27 '19 02:01

Alexander Mills


People also ask

Is hibernate a good ORM?

Object/Relational Mapping Hibernate ORM enables developers to more easily write applications whose data outlives the application process.

Is Hibernate an ORM?

Hibernate is an open source object relational mapping (ORM) tool that provides a framework to map object-oriented domain models to relational databases for web applications.

What is the difference between ORM and hibernate?

Hibernate is an object-relational mapping solution for Java environments. Object-relational mapping or ORM is the programming technique to map application domain model objects to the relational database tables.

What is Hibernate object relational mapping ORM framework?

Hibernate ORM (or simply Hibernate) is an object–relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database.


1 Answers

@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.

like image 188
Alexey Soshin Avatar answered Sep 30 '22 06:09

Alexey Soshin