Wednesday, July 11, 2012

Huh, OpenJPA?

Purpose of this post is primarily to help add hype around OpenJPA (there is lack of hype, from community and Apache/OpenJPA all the same).

Contrary to the plain vanilla JPA implementation vibe the project site gives off, OpenJPA might actually have its own distinctive virtue.   A popular phrase among Haskellers perhaps, "do one thing, and do it well."

Configuration might be a little daunting at first because it takes a rather different approach from such that Hibernate and EclipseLink share.  But that aside it has worked well for me (after about two-weeks use for development purposes) and perhaps most importantly for me is that its documentation is awesome.  The content feels well-thought out.  It comes in the usual online help and PDF formats.  Haven't you ever stumbled across duplicate or outdated content somewhere in EclipseLink's wiki-style 'Documentation Center'?

On that note, actually Hibernate comes with similar documentation formats as well.  The difference is that with Hibernate documentation feels more like a long tutorial (a JBoss thing perhaps?) while with OpenJPA (an Apache thing perhaps?), documentation is more formal.

Anyway one nice feature I've recently found is a native UUID generator assignable via the usual GeneratedValue annotation.  Excerpt from the documentation:

OpenJPA also offers additional generator strategies for non-numeric fields, which you can access by setting strategy to AUTO (the default), and setting the generator string to:
  • uuid-string: OpenJPA will generate a 128-bit type 1 UUID unique within the network, represented as a 16-character string. For more information on UUIDs, see the IETF UUID draft specification at: http://www.ics.uci.edu/~ejw/authoring/uuid-guid/
  • uuid-hex: Same as uuid-string, but represents the type 1 UUID as a 32-character hexadecimal string.
  • uuid-type4-string: OpenJPA will generate a 128-bit type 4 pseudo-random UUID, represented as a 16-character string. For more information on UUIDs, see the IETF UUID draft specification at: http://www.ics.uci.edu/~ejw/authoring/uuid-guid/
  • uuid-type4-hex: Same as uuid-type4-string , but represents the type 4 UUID as a 32-character hexadecimal string.
These string constants are defined in org.apache.openjpa.persistence.Generator.

So there goes my preliminary hype around OpenJPA.