Monday, July 29, 2013

JPA EclipseLink vs JPA Hibernate Default Configuration Investigation

Recently, I just came in front of a big surprise. In a JEE application, developed on JBoss 7 AS and JPA with the embedded Hibernate as persistence provider, most of the complicated queries took from 2s  to 3s.
One day had the idea to test the application in Glassfish 3.1.2 with the embedded EclipseLink as persistence provider.

The results were stunning. The second setup could provide the same query in 200ms to 300ms. So, I had to find if was the Application Server who did the difference or the persistence provider. I had the intuition that the provider made the difference.
So, I did the same test but now I used the JBoss 7 AS with the EclipseLink. And that's it. 

Noteworthy is to mention that both configuration were set to default.
OK now, I feel some reactions from you. "But EclipseLink has enabled the Shared Object Cache by default, that's why performs better", you say. And my response is: "I activated the EHCache and the results were more or less the same".
Of course, that case requires more investigation, but I recommend to those who have developed an independent provider JEE application and use Hibernate, give a chance to EclipseLink.

In my case, for some reason Hibernate made 10x queries to fetch the same data in contrast to EclipseLink. Most of you, will say that I had the associations with FETCH.Eager, but guess what? I don't. That was the reason that I had so many methods in my Database Service. Also, EclipseLink provides the feature to bring any lazy objects by creating a Read-only connection (no transaction needed) without using extended EntityManager. Why not? Because, extended EntityManagers requires Stateful Beans which need a lot of resources. Bad idea for a JEE application with many users access it.