Hello, You can create a method and annotate it with @PostPersist @PostUpdate @PostRemove (also pre) depending on your needs.
Then access the old and new states of the entity with PersistenceCapable pcCurrentState = (PersistenceCapable) pCurrentState; StateManagerImpl sm = (StateManagerImpl) pcCurrentState.pcGetStateManager(); PCState state = sm.getPCState(); SaveFieldManager sfm = sm.getSaveFieldManager(); PersistenceCapable pcOldState = sfm.getState(); You then cast the states to your entity oldState = (Entity) pcOldState; newState = (Entity) pcCurrentState; I do believe you need to add something to your persistence.xml to allow this to work, but I don't recall for certain. Hope this helps John > -----Original Message----- > From: Klesk [mailto:c...@hotmail.com] > Sent: Dienstag, 4. Juli 2017 11:14 > To: users@openjpa.apache.org > Subject: Re: Attribut change listener > > My workaround (needs to be deeply tested): > > > Klesk wrote > > @Test > > public void testProxy() throws Exception { > > final EntityManager em = factory.createEntityManager(); > > final SUti entity = em.find(SUti.class, 1); > > > > final ProxyFactory proxiter = new ProxyFactory(); > > proxiter.setSuperclass(entity.getClass()); > > proxiter.setHandler((instance, method, wrapper, args) -> { > > instance = entity; > > wrapper = entity.getClass().getMethod(method.getName(), > > method.getParameterTypes()); > > if(method.getName().startsWith("set")) { > > final String methodName = method.getName(); > > final Object previous = > > instance.getClass().getMethod("get" + > > methodName.substring(3)).invoke(instance); > > System.out.println("changed: " + previous + " -> " + > > args[0]); > > } > > return wrapper.invoke(instance, args); > > }); > > > > final SUti mock = (SUti) proxiter.create(new Class[0], new > > Object[0]); > > assertEquals("AAAA", entity.getUtLibuti()); > > assertEquals("AAAA", mock.getUtLibuti()); > > mock.setUtLibuti("test"); > > assertEquals("test", entity.getUtLibuti()); > > assertEquals("test", mock.getUtLibuti()); > > } > > > > > > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Attribut-change-listener- > tp7590226p7590227.html > Sent from the OpenJPA Users mailing list archive at Nabble.com.