few months ago, I was teaching a class on JDBC. After a particularly tedious JDBC lab, I alluded to the existence of many Java persistence frameworks to help Java developers avoid some of the tedious and error-prone JDBC coding to help get Java objects in and out of a relational database. I was asked, "Which is best?" My response was the standard instructor/consultant answer: "Well, it depends." I could tell by their facial expressions that my answer was less than satisfactory. There are some differences in the way each performs the work, but the results are supposed to be the same; at least in the general notion of getting data in and out of the database.
What follows is a study I have made over the past few months to more suitably answer the question posed by my students and others looking at Java persistence options. This is not an article that will teach you how to persist Java objects in each of the technologies; although the attached code provides a couple of examples in each framework that may help in that endeavor. Instead, this article considers the following questions:
- How easy is it to obtain and setup the persistence frameworks?
- What is the learning curve for each framework? Are there ample resources for help and support when using the frameworks?
- How well do the frameworks adapt to existing database and object models?
- How does each framework perform?
- What's the impact of the frameworks on the amount of Java code, configuration files, and byte code footprint?
- How do the frameworks deal with persistent objects across transactions?
- Do the frameworks assist with cascading operations across object relationships?
Is there a clear winner or choice for your project? Is there a Java persistence framework that can claimed the title of "Best-in-breed"? Unfortunately, as you will see, the answer to "which framework is best" might still be "it depends." In fact, as you will also see, there are a lot of caveats and footnotes in my results. A direct comparison is possible, but not under the exact same conditions in all casesthus the need to qualify the results. However, I do think you will find the results a good reference for understanding some of the strengths and weaknesses of the frameworks and a good place to start when examining Java persistence options. If for no other reason, the code and information provided with this article can help you more quickly devise your own tests.