Member-only story
Efficiently loading associations with JDBC, Hibernate and EclipseLink
Usually web applications serve to save data to a database and to visualize already saved data. What is the best way for a Java application to interact with a database? There are two options — JDBC or a library implementing JPA. Instead of speculating, I make a simple realistic experiment.
I suppose applications load data more often than save. So in this post I compare three options for loading relational data from a database. I compare JDBC to two JPA implementations — Hibernate and EclipseLink. The two JPA libraries are not equivalent. Some basic tasks that can be done in Eclipselink cannot be easily achieved with Hibernate, and conversely.
I will use the sample data model that resembles the Country
-Department
-Employee
relationships used in tutorials.
In my sample model, each country has many authors. Each author is a resident of one country. An author can create many posts. Each post is by one author. Chained one-to-many or many-to-many relations are omnipresent in real-life data. I do…