For future reference, I resolved the issue through trial-and-error: you
should add LifecycleListeners via the BrokerFactory.addLifecycleListener
method.

You can do this for all created instances BrokerFactory by listening to

OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.cast(entityManagerFactory);
emf.getConfiguration().getBrokerFactoryEventManager().addListener(this);

  public void eventFired(BrokerFactoryEvent event) {
        if(event.getEventType() ==
BrokerFactoryEvent.BROKER_FACTORY_CREATED) {
            event.getBrokerFactory().addLifecycleListener(listener, new
Class[] { Entity.class } );
        }
    }

Regards...

Ricardo Gladwell <[email protected]>


2009/9/9 Ricardo Gladwell <[email protected]>

> I'm trying to add a PersistListener to my OpenJPA EntityManagerFactory like
> so:
>
> OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
> OpenJPAPersistence.cast(entityManagerFactory);
> emf.addLifecycleListener(listener, classes);
>
> However, when I then call my DAO to update the my entity like so:
>
> entity = dao.readValue(id);
> entity.setValue("NewValue");
> dao.updateValue(entity);
>
> My PersistListener is never called. Am I doing something wrong?
>
> Using debugging introspection I identified that my PersistListener has been
> successfully added to the DAO internal JDBCBrokerFactory _lifecycleListeners
> HashMap.
>
> Can anyone advise if I'm doing something wrong?
>
> TIA...
>
> Ricardo Gladwell <[email protected]>
>

Reply via email to