Vertx JPA / Hibernate support

3,219 views
Skip to first unread message

J Guedouar

unread,
Jan 15, 2016, 7:16:51 PM1/15/16
to vert.x
Hi all,


I know that the JDBC client exist, but what about JPA ? Because it is really annoying to write SQL queries manually...


Thx !

Alexandru Ardelean

unread,
Jan 16, 2016, 12:21:30 PM1/16/16
to vert.x
Nobody stops you to configure hibernate with vertx, yet I wouldn't do it for a production based code.

Vertx's power is that it is light and non-blocking. Hibernate is neither. So building vertx with hibernate, would strip away vertx's advantages.

Anyway, if you really want it, I have a sample of configurating a vertx-spring-jpa-hibernate-rest services (I did it just to experiment spring more with vertx) and I did some load tests on top of it (don't recall the results, but they were better than tomcat). 

Honestly, I would recoment JOOQ for vertx. It fits like a glove.
Here is why:
Jdbc is blocking. Any request to database via jdbc will block your verticle. Unless you make it a worker. In that case, you do not have much to win or gain.
Hibernate is a full ORM bloated framework. It has high overhead in terms of performance, and is also blocking (using jdbc)

JOOQ can very easy map results from sql queries into directly a dto. No longer ORM problems that you must do a conversion manually to business objects.
JOOQ is a lot of fun to work with. It is light, and can be used with fibers, which is non blocking. Fitting perfectly with vertx :).

As an example, you can start from here:

Thomas SEGISMONT

unread,
Jan 16, 2016, 12:23:01 PM1/16/16
to ve...@googlegroups.com
You can use Hibernate in a worker Verticle. This has been asked a few days ago.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/067a2cfd-22d4-4b8a-a710-ed11dbc5ef4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

J Guedouar

unread,
Jan 16, 2016, 4:28:16 PM1/16/16
to vert.x
Thank you for your explanations ! 

I think JOOQ fits better because like you said we dont want blocking threads.
Also Hibernate is not light and relies to the EntityManager ( JPA ) which is not also light and blocking.

Thank you for your example, is it possible to have the same without spring but using HK2 inject ?

Thx ! 

Arnaud Estève

unread,
Jan 17, 2016, 5:52:36 AM1/17/16
to vert.x
I've tried multiple times to understand how properly using Hibernate/JPA in vert.x-web applications.

The starting point would be implementing the "session-per-request" pattern where you're opening a session (what they're calling a "logical transaction") in the very first vertx-web handler, then closing it in the very last handler.

That works, but the main problem is lazy loading. You cannot be sure what the user will do with the Java POJOs, maybe, within its handler implementation, he is gonna call thePojo.getSomeCollection() which is gonna lazy load a full collection. And here's the problem, there's a risk, without even noticing, that he'll block the event-loop.

I've read that GORM could be run in an async manner. And thus I think it could be a better fit for ORM-related stuff within Vert.x. 

I still have to figure out how to embed GORM in a Vert.x application, but I really think this would be a very cool addition to the stack. If anyone has thoughts to share, or is interested in this we could maybe join our efforts.

Just let me know :)

Jihad Guedouar

unread,
Jan 17, 2016, 11:08:07 AM1/17/16
to ve...@googlegroups.com

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/WHdm5TkDCi0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.

J Guedouar

unread,
Jan 18, 2016, 10:14:33 AM1/18/16
to vert.x
I like your idea with JOOQ !

I think its possible to combine with RxJava and HK2 for DI.

JOOQ was exactly what i was looking for, instead of using requests like: "SELECT * FROM ...", I could simply use the DSL context with the @Inject annotation to be able to query with JOOQ !

Thx for the solution !


Le samedi 16 janvier 2016 18:21:30 UTC+1, Alexandru Ardelean a écrit :

Guido Medina

unread,
Jan 21, 2016, 7:53:27 AM1/21/16
to vert.x
I'm using EclipseLink with Akka + Vert.x, although being aware of what I'm doing and avoiding lazy loading, my domain is not that big and I make sure I do my try with my own closeable entity manager.
I'm using worker verticles and a separated dispatcher for Akka so problem solved, I don't like Hibernate TBH, I find EclipseLink lighter and oriented to JPA 2, simple and fast; or fast enough.

I'm also using HikariCP as datasource provider which is both predictable and fast http://brettwooldridge.github.io/HikariCP/ludicrous.html

I was using Sql2o and would at used JOOQ but I needed post load events which is nicely implemented on JPA 2.

Give EclipseLink a try, it is very efficient IMHO; again, I don't like Hibernate because it started as one thing and then covered other aspects like JPA and so on.

I have used EclipseLink on the last two jobs I have worked and I have no regrets, I even mixed it with Riak as I needed post load/update events to also touch Riak keys which was something I couldn't do with Hibernate.

HTH,

Guido.

Guido Medina

unread,
Jan 21, 2016, 7:54:29 AM1/21/16
to vert.x
Also remember you will be exposing Json data to your web/REST layer so lazy loading is not a problem if your Json result is created before you close the entity manager.

Chris Kaminski

unread,
Feb 3, 2016, 4:13:17 PM2/3/16
to vert.x


On Saturday, January 16, 2016 at 12:21:30 PM UTC-5, Alexandru Ardelean wrote:
Honestly, I would recoment JOOQ for vertx. It fits like a glove.
Here is why:
Jdbc is blocking. Any request to database via jdbc will block your verticle. Unless you make it a worker. In that case, you do not have much to win or gain.
Hibernate is a full ORM bloated framework. It has high overhead in terms of performance, and is also blocking (using jdbc)

JOOQ can very easy map results from sql queries into directly a dto. No longer ORM problems that you must do a conversion manually to business objects.
JOOQ is a lot of fun to work with. It is light, and can be used with fibers, which is non blocking. Fitting perfectly with vertx :).

Is not the vertx-jdbc-client asynchronous?  I thought using that removed the need for having worker verticles?   

Clement Escoffier

unread,
Feb 4, 2016, 2:01:30 AM2/4/16
to ve...@googlegroups.com
Hi,

Yes the vertx-jdbc-client is asynchronous and you don’t need to be a worker verticles to use it.

Clement


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Dixie Sebastian

unread,
Mar 2, 2016, 8:44:37 AM3/2/16
to vert.x
Hello Guido,

Can you please help me or point me to a place where I can see samples of services using vertx-jdbc with eclipselink.

I'm not sure on how to have the datasource from the vertx shared jdbc instance to tie-up with the persistence xml.

Regards,
~Dixie.
Reply all
Reply to author
Forward
0 new messages