adam bien's blog

Making JPA 2.0 better - thinking loud about refreshAll and clear(Entity) 📎

JPA 1.0 spec is lean, provider independent, powerful and usable inside, as well as inside a n EJB-Container.  However in some circumstances the JPA 1.0 requires still some workarounds:

 

1. I miss the method clear(Entity entityToDetach) for a particular entity. I use JPA in an unmanaged environment (Java SE 6) - such a method would simplify detaching the passed entity without clearing the whole cache. This is especially useful in stateful environments, where the Entities are bound to the UI (e.g. JSF, Seam, Rich Clients). JPA 1.0 only supports the method clear(), which detaches all entities or the whole entity manager… In my opinion it would be a nice extension for JPA 2.0.

 

2. I miss the refresh() (or refreshAll()) as well. In this case all attached Entities of an EntityManager should be refreshed. Now you have to do the bookkeeping of all known entities and refresh them on demand. This could be actually really useful for refreshing the whole workspace and preventing optimistic collisions. Of course refreshing the whole workspace could be slow, however keeping track of all entities and refreshing them sequentially is even slower.

 

What was your experience so far? Your feedback is appreciated, we are discussing these topics now in the JPA-EG - so you could change the future :-).