users@glassfish.java.net

Best way to programmatically discover persistence units?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Tue, 15 Nov 2011 10:01:57 -0500

What is the best way to be notified when Glassfish creates a new
persistence unit?

I am working on some integration testing utilities and I need a way to
programmatically clear a JPA cache. Working backwards, I can do this if I
can get an EntityManagerFactory.

I was thinking that I'd have a stateless or singleton EJB that I deploy to
embedded Glassfish alongside the EJB that I'm actually testing. Then the
test infrastructure could tell this bean to clear JPA caches for all
persistence units it could discover or otherwise know about. That bean
would either have all known EntityManagerFactories injected into it in some
way (via @Inject?) or would call some Glassfish-specific API somewhere to
get them, or would implement some kind of listener interface and could be
notified when a new persistence unit was created...

My first thought was that there might be a way to do it with BeanManager,
but sadly no. Perhaps there's some Glassfish API I'm missing here that
makes this obvious? Something in the deployment packages, perhaps?

Best,
Laird

-- 
http://about.me/lairdnelson