openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From is_maximum <>
Subject Re: regarding StoreListener
Date Wed, 04 Mar 2009 19:02:30 GMT

Hi Michael,

As far as I know these are entity listener and we have to declare our
listener for each entity and I think this is not a good idea. consider that
we have nearly 30 entities and it may be added in the future we don't like
to declare a listener for each pre-update, pre-remove and pre-persist,
instead we need a listener just like StoreListener in OpenJPA in which we
are notified by any changes in any entity and then we can find dirty fields
and old/new values so we can save the history of any changes. Keeping this
history is inevitable and very important to our customers

Now the StoreListener I already stated works fine but the problem is that
before any invocation of one of merge(), delete() and persist() of
EntityManager we have to add this listener to the EM and I think this is a
bit messy and not a good idea.  Sorry maybe because of my poor English you
could not understand me very well if so ask me to put the snippet code here
to clarify everything. Now I'm at home but tomorrow I will post the code.


Michael Dick wrote:
> Hi,
> The JPA specification defines several listeners which can be configured
> via
> orm.xml or annotations in your entity classes. Here's a quick view of the
> available listeners :
> The following annotations are defined to designate lifecycle event
> callback
> methods of the corresponding
> types.
> • PrePersist
> • PostPersist
> • PreRemove
> • PostRemove
> • PreUpdate
> • PostUpdate
> • PostLoad
> Section 3.5 of the JPA 1.0 specification covers how these listeners are
> used
> in more detail.
> Do you need a listener for any other lifecycle event for your entity, or
> does this cover everything you need?
> -mike
> On Wed, Mar 4, 2009 at 2:02 AM, is_maximum <> wrote:
>> Hi
>> First I don't know why there is no useful document on these sort of
>> listeners and how to use it.
>> Second after toiling I was able to find dirty fields and fire the
>> pre-update
>> event. This is for a logging service we have to implement for our
>> application but now the problem is that if you want to listen to an
>> store-event (pre-update, pre-delete ...) you need to cast the em into
>> openjpa-em and then add your listener to it. First I did it in
>> @PostConstruct callback method but soon I found that this method will be
>> called once each time the container instantiate my stateless so after
>> that
>> the listener won't work at all.
>> now I have implemented some save() update() and delete() method as DAO
>> interface and before each method I add this listener to.
>> The problem is that I think this way of adding listeners is not correct.
>> I've already used Hibernate and they have a simple XML file in which you
>> can
>> simply define your desired listeners and they are guaranteed to work each
>> time a CRUD operation being applied
>> Is there anythink like that in OpenJPA or Do we need to open an issue in
>> JIRA and request such feature?
>> thanks
>> --
>> View this message in context:
>> Sent from the OpenJPA Users mailing list archive at

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message