openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Gladwell <ricardo.gladw...@gmail.com>
Subject Re: Problem with OpenJPA Life-cycle Listeners
Date Thu, 10 Sep 2009 15:05:41 GMT
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 <ricardo.gladwell@gmail.com>


2009/9/9 Ricardo Gladwell <ricardo.gladwell@gmail.com>

> 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 <ricardo.gladwell@gmail.com>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message