openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <>
Subject Register listener once and only once
Date Tue, 16 Oct 2007 00:27:50 GMT
The OpenEJB JPA based CMP engine is a wrapper around an  
EntityManger.  The engine is designed to get out of the way of the  
JPA implementation so the performance is only a function of the JPA  
implementation.  In the engine we do not have a cache or beans or  
even the entity managers. Instead we rely on the entity manager to  
cache the beans and the entity manger factory (or JTA based wrapper)  
to cache the entity managers.

The Problem:
I need to register a lifecycle listener to perform CMP callbacks like  
ejbLoad and ejbStore and need to do this once to avoid duplicate  
callbacks.  The problem is there seems to no way to determine if the  
lifecycle listener has already been added to the EM without  
maintaining a list of registered EMs.  Currently, I'm using a  
WeakHashMap<EntityManager,Object> to determine if I have already  
registered, but am looking for a cleaner way.

Possible Solutions:
o Add an isRegisteredLifecycleListener method to the EM, and I check  
it before add
o Add a getLifecycleListeners method to the EM, and I search the list  
before add
o Add lifecycle listener at the EMF level which it is automatically  
added to all created EMs (of course I'll need a way to uniquely do  

Other Solutions? Ideas? Comment?


View raw message