My article Basic Java Persistence API Best Practices was published on Oracle Technology Network (OTN) today. In this blog entry, I intend to provide a little background and extra information that I could not squeeze into the article itself.
As with most "best practices," the items discussed in this article are generally the "best" approach in my experience. That being said, almost nothing is always the better regardless of the circumstances and some practices closer to always being the best than are others. The focus of this article was on "basic" or relatively easy-to-implement practices that typically provide later benefits. In other words, I tried to cover JPA techniques and approaches that provide significant value for little extra effort or cost.
The focus on "basic" also meant that the article is largely targeted at developers just learning or starting to use JPA. More advanced JPA best practices are covered in JPA - Best Practices and Tips (2007 JavaOne Conference presentation referenced in my article), Java Persistence API - Portability Do's and Don'ts (another 2007 JavaOne Conference presentation referenced in my article), Java Persistence API: The Good, the Bad, and the Ugly, and the "under construction" EclipseLink FAQ on JPA Best Practices.
My original draft of this article was over twice as long as the final version. One of the technical editors pointed out (rightly) that the original version was too long. The final version is much easier to read quickly and meets my usual expectation that tighter and more concise articles are preferable to longer-winded articles. The only drawback to removing so much content is that I was forced to remove coverage of some things I thought were useful for developers just learning JPA, but which were not as significant as what did make the cut. I hope in future blog entries to cover some of these details that did not make the final article. In addition, I also plan to use this blog to provide additional background on why certain practices are "best" in my opinion and to provide source code examples to illustrate some of these best practices.
I mentioned/quoted/paraphrased Mike Keith a couple times in this article. His Colorado Software Summit 2007 presentations on JPA are both related to "JPA best practices" and are now available online. They are called JPA Portability: What You Should Know When Writing Portable JPA Applications and EJB 3.0 Puzzlers (focus is on JPA specifically rather than the more general EJB 3).
Two recent and highly detailed blog entries that look at subjects I touched upon in this article are Why Sometimes a Reference to an Entity Manager Inside JPA Entities is Needed and The Tense Relationship Between JPA, Enums, and Generics.
Finally, with JPA 2.0 getting more attention, there is much to look forward to in future Java Persistence API development.