I would like introduce JavaEEUtils

In my JPA projects, I often started with doing the same things:

Create some basic JPA entity classes that all others extend. With last project I moved them into a separate project which I called JavaEE utils.

They include the following base classes:

  • PersistentEntity:
    A superclass for all persistent entities. Defines a Log id, a version field and a createdBy/At combination.
  • EntityWithNaturalKey:
    To be used for entites that not only have the tecnical key from PersistentEntity, but also a functional key.
    Used when Lists of these entites are merged in DB.
  • AuditableEntity:
    Defines updatedAt/By combination.

Additionally I took the idea from an Adam Bien presentation and this post and created a mechanism to use the EntityManager inside entity beans

  • In your StatelessSessionBean use the EnableEntityManagerInterceptor interceptor.
  • When you know need an EntityManager inside your domain objects, just call EntityManagerHelper.get().

The code can be found at http://code.google.com/p/javaeeutils/

Maven:

Tell me what you think about it…