Well so we can define a listener for all the entities.

that's pretty good but one more question is that if we use these entity
listeners, can we still find out those fields that has been changed (dirty
fields) for example in pre-update and persist the result in DB. As far as I
know, inside the callback methods the context has been closed so you can't
access the entity manager so we have to get it in a way to persist the
result. Can we place the codes we are using in StoreListener inside the
callback methods without any problem?



Michael Dick wrote:
> 
> Hi,
> 
> I think I understand your concern. You're looking for a default set of
> listeners which apply to all your entities. This is also supported by the
> JPA specification. Relevant section :
> 3.5.7.2 Specification of the Binding of Entity Listener Classes to
> Entities
> The entity-listeners subelement of the persistence-unit-defaults element
> is
> used to
> specify the default entity listeners for the persistence unit.
> 
> Here's an example from one of our unit tests :
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
>                     http://java.sun.com/xml/ns/persistence/orm_1_0.xsd";
> version="1.0">
> <persistence-unit-metadata>
>    <persistence-unit-defaults>
>        <entity-listeners>
>             <entity-listener
> class="org.apache.openjpa.persistence.annotations.common.apps.annotApp.ddtype.DefaultCallbackListener">
>                  <pre-persist method-name="prePersist" />
>                  <post-persist method-name="postPersist" />
>                  <pre-remove method-name="preRemove" />
>                  <post-remove method-name="postRemove" />
>                  <pre-update method-name="preUpdate" />
>                  <post-update method-name="postUpdate" />
>                  <post-load method-name="postLoad" />
>             </entity-listener>
>         </entity-listeners>
>    </persistence-unit-defaults>
> </persistence-unit-metadata>
> . . .
> 
> Is that more what you're looking for?
> 
> -mike
> 
> 
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/regarding-StoreListener-tp2420847p2425189.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to